Label statement in AS3

In ActionScript 3 a label statement is used to associate a statement with an identifier which can be referenced by both the break and continue statements to exit a block of code. Basically, a label statement is the equivalent of goto in C – yes, I know what you’re thinking!

For instance, in a nested loop, a break or continue statement will only break out of the immediate loop and will not skip the entire series of loops (the end of the outer most loop) as one might expect. Labels are used as identifiers for an entire block of code from which a break or continue statement can reference in order to skip the entire series of loops or a specific loop from within a series of nested loops.

An example of how a label statement can be used to break out of an outer loop is as follows:

A label may also be referenced by a break statement to exit a block statement as follows:

Typically, it is rare that you would need to use the label statement, however, in certain situations if it is necessary and can be justified, the label statement provides a convenient way to exit code.

{Sorry, Comments are currently Closed! }