The continue statement and labels

0 Flares Twitter 0 Facebook 0 Google+ 0 Email -- Filament.io 0 Flares ×

The continue statement skips the rest of the code inside a loop and starts at the beginning of this loop as if the end of the loop had been reached normally.
Thus, the code after the continue statement in the code below will never get executed by flash:
[sourcecode language=’cpp’]
for(var i:int = 0 ; i < 10 ; i++) { trace( "before continue" ); continue; trace( "after continue" ); } [/sourcecode] The "trace( “after continue” );” never gets executed.

Now, as with the break statement, you can set labels for loops and specify them in your continue statement:
[sourcecode language=’cpp’]
first_for_loop: for(var i:int = 0 ; i < 10 ; i++) { second_for_loop: for(var i2:int = 0 ; i2 < 10 ; i2++) { trace( "before continue" ); continue first_for_loop; trace( "after continue" ); } trace( "after nested loop" ); } [/sourcecode] This way, the "trace( “after continue” );” and “trace( “after nested loop” );” never get executed. The continue statement tells flash to skip the rest of the code in both loops and go at the beginning of the first loop labeled “first_loop_for“.

0 Flares Twitter 0 Facebook 0 Google+ 0 Email -- Filament.io 0 Flares ×

Leave a Comment

*