flash/As3.0 | 2006/08/23 15:32

ActionScript 3 introcuduces labels, new identifiers that can be associated with loop blocks. Why would you want to identify a loop block? Because you can use that identifier as a target for break and continue commands. Consider two loops where one is nested in the other. If at some point you want to exit both loops while in the nested loop, you can't. The break command only exits the current block. A common workaround is to use a flag variable to be able to check that, when in the first loop, if that should be exited as well

중첩된 loop의 경우 기존에는 한번에 loop를 벗어나는것은 할수 없었다.
다만 flag를 이용해 벗어나는 경우가 유일한 방법이다. 이젠 그럴필요 없다.
As3.0 에서는 Label Statements 를 이용해 전체 루프를 빠져나올수가 있다.

As 2.0 ActionScript Code:

var i:Number;
var j:Number;
var exit:Boolean = false;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
if (i > 3 && j > 3) {
exit = true;
break;
}
}
if (exit) {
break;
}
}

-----> exit 라는 flag 변수를 이용해 체크한다.


As 3.0 ActionScript Code:

var i:Number;
var j:Number;
mainLoop: for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
if (i > 3 && j > 3) {
break mainLoop;
}
}
}

------> mainLoop 의 label 을 지정해 한번에 loop 탈출.....지저분하게 변수를 사용하지 않는 명확한 방법이다.


 
 
태그 : , ,
이 글의 관련글(트랙백) 주소 :: http://kimkijeung.com/trackback/51

Name 
Password 
Homepage 
  secret
Comment 
  글쓰기


[PREV] [1] ... [55][56][57][58][59][60][61][62][63] ... [105] [NEXT]

 
전체 (105)
flash (74)
math&physics (4)
programming (11)
Flex2 (1)
Mac (2)
photo (0)
project (6)
주저리주저리 (3)
유용한 자료들 (1)
diary (0)
Book (1)
web (2)
«   2009/01   »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31