Description

11-22 Illustrates the break statement. Note the the loop that begins in line 13 is an infinite loop. The break in line 18 allows us to exit this loop. In general the break statement exits the immediately enclosing loop. This loop could be a for, do, or while loop.

24-59 Illustrates the switch statement. This can be used in place of a lengthy string of if-else-if statements. Note that the value used inside the parenthesis (line 48) can be a formula or a variable, but it must evaluate to an integer value. In this example when the menuOption matches a case value, the corresponding code is executed. The break statement is necessary, otherwise execution continues on to the next case statement.

64-74 Illustrates the continue statement. This can be used to jump back up to the top of a loop (do, while, or for). In the example above when the secondNumber is 0 (line 69), the continue causes control to jump back up to the for loop (line 65), where the "update" part of the for for loop is executed and the loop attempts to execute again.

Note that the break and continue statements are a convenience and are not absolutely necessary. In each case a combination of some "flag" variables and if statements can accomplish the same thing.