POSITION:028,114
COLOUR:STANDARD
TEXT:00,Both the "for" and "while" statements can be nested, meaning that you
TEXT:16,can have smaller loops within larger ones. However, the nested "while"
TEXT:16,and "for" statement levels should have correctly matching "end while"
TEXT:16,and "end for" statements.
TEXT:32,You can force both a "while" and a "for" statement to end early using
TEXT:16,the "exit" statement. The loop ends at the moment the "exit" statement
TEXT:16,is executed. The program will then resume at the next statement following
TEXT:16,"end for" or "end while". The "exit" statement is best used as
TEXT:16,either an "emergancy brake" when something unexpected comes up, or for
TEXT:16,creating a loop that needs to end for a set of reasons uniquely separate
TEXT:16,from each other. A program demo shows the "exit" statement in action.
TEXT:32,You have now learned everything you need to know to control the course of
TEXT:16,program execution. These tools will be valuable in the next chapter, when
TEXT:16,you learn how to accept data from the keyboard.
