Break [(<level>)] |
The Break
statement can be used to exit from a loop or from the Switch
statement. If you call Break
inside a loop or a Switch statement, then
Hollywood will exit from this control structure. An example:
For k = 1 To 100 DebugPrint(k) If IsKeyDown("ESC") = True Then Break Next |
The above loop counts from 1 to 100 but can be aborted at any time by pressing the escape key.
Using the optional argument level
, you can also finish higher loops. If
you do not specify level
Hollywood will assume 1 for it. This means that
the nearest loop will be finished. If you use higher values for level
Hollywood will traverse the loops upwards. An example:
For x = 1 To 100 For y = 1 To 100 DebugPrint(x, y) If IsKeyDown("ESC") Then Break(2) Next Next |
This code uses two nested For loops and checks in the second loop if the
escape key was pressed. To finish both loops, we have to use a Break(2)
statement now because the normal Break
would only finish the inner loop
which would be started right again because there is still the outer loop.
Please note: If you specify the optional argument level
it is obligatory
to put parentheses around it.