Difference between revisions of "Using break to Exit a Loop"
Line 1: | Line 1: | ||
[[Category:Program_Control_Statements]] | [[Category:Program_Control_Statements]] | ||
− | | + | {{HelpFiles}} |
===Using break to Exit a Loop=== | ===Using break to Exit a Loop=== |
Latest revision as of 08:16, 14 December 2011
Using break to Exit a Loop
It is possible to force an immediate exit from a loop, bypassing any code remaining in the body of the loop and the loop’s conditional test, by using break statement. When a break statement is encountered inside a loop, the loop is terminated, and program control resumes at the next statement following the loop. Here is an example:
{ number i = 1; while (i<10) { if (i==6) break; print(i); i = i + 1; } print("Counting completed."); } The output from the script is shown here:
|