When a programmer writes a counted loop, there is automatically an exit out of the loop, which is when the control variable is greater than the ending variable. As well as this, there are also other exits from a counted loop using the keywords exit when. Why would you use exit when in a loop statement with already an exit? The reason is so that the user of the program can exit out of that loop statement anytime they want. They do not necessarily have to use the program until the control variable is greater than the ending variable. Here is an example:
for color : 1 .. 10 put “color?” .. get color put color exit when color = “stop” end for
As you can see in the example above, there are two ways to exit from this for loop. The first option is by using the program until the control variable is equivalent to the ending variable. The second option, is when the user types in “stop”, the program automatically closes the for loop. This variation of the for loop provides more user interface and more options for the user because they can choose to end certain things when they wish. Providing two ways of exiting from the loop can make your program seem more professional but as well as prevent computer crashes.