Exiting loops early | |||
|
There are three ways to exit a loop prematurely. The first (and the one which would be cleaner) is to include some provision in the loop expression for exiting the loop. This could take the form of using another variable in the expression and combining it with the main loop expression using logical operators such as AND or OR. Of course, this is not always possible, e.g. in For...Next loops. Another possibility would be to change the value of the parts of the loop expression so that the loop terminates. For example, you could set the value of the variable in a For loop to the value of the second expression, which would cause the loop to end. Examples of these are shown below: The final possibility is to use the Pop command. This makes the program "forget" about the current loop, but it also means that you must jump past the command which is used to end the loop (and this will be described on the next page). The format of the Pop command is:
Where <Loop type> can be Gosub, For,
Select, If, While
or Repeat. Actually, you only need to use Pop
with the first three of those loop types, but no harm will come from using it with the last three
(which have been included for completeness anyway). Full examples for the Pop
command are given on the next page.
| |||
|
Installation | Troubleshooting | Programming | Archives | Links Page last modified: 6th February 2002 |