Notes: Differences of Break And Return
Just a little note to myself (after wasting an hour). When running a loop inside a function, using break merely terminates the loop and not the function itself. To terminate the function, use return instead.
The code below, when the if statement is true will terminate the function. If the return is replace with a break, only the for loop terminates, and updateCurrentThumb( 0 ) is still called/performed.
private function findPosition( clip:MovieClip){
for( var i:Number = 0; i < thumbs.length; i++ ){
if( clip.getModel() == thumbs[i].getModel() ){
updateCurrentThumb( i );
return;
}
}
updateCurrentThumb( 0 );
}
You’re currently reading “Notes: Differences of Break And Return”, an entry on Visual Gratis
- Published:
- 07.14.07 / 12am
- Category:
- Actionscript, Flash, Notes
- Tags:
- Post Navigation:
- « Wormhole
Old Stuff, New Post »