
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Stopping a Loop Prematurely
|
173
The break Statement
The break statement ends execution of the current loop or switch statement (as we
saw in Chapter 7). It has the modest syntax:
break
The only requirement is that break must appear within the body of a loop or switch
statement.
The break statement provides a way to halt a process that is no longer worth com-
pleting. For example, we can use a for-in loop to build a form-checking routine that
cycles through the input-text variables on a timeline. If a blank input field is found,
we alert the user that she hasn’t filled in the form properly. We can abort the pro-
cess by executing a break statement. Example 8-3 shows the code. Note that the
example assumes the existence of a movie clip called
form_mc that contains a series of
declared input variables named
input01_txt, input02_txt, and so on.
The continue Statement
The continue statement is similar to the break statement in that it causes the current
iteration of a loop to be aborted; but, unlike break, it resumes the loop’s execution
with the next natural cycle. The syntax of the continue statement is simply:
continue
In all types of loops, the continue statement interrupts the current iteration of the
loop body, but the resumption of the loop varies slightly depending on the type of
loop