| None. |
|
Closes a For loop and sends control back for the next pass. Every For needs a matching Next. When execution reaches it the counter is moved on by the Step amount and tested against the To limit; if there is another pass to make, control jumps back to the top of the loop, otherwise it carries on below the Next. Next also closes a For Each loop, where instead of stepping a number it moves to the next object in the type's list. Write it on its own. Unlike most BASIC dialects, Blitz does not want the counter's name after it - Next i is a compile error, not a nicety. Nested loops sort themselves out because each Next pairs with the nearest unfinished For, so keep the indentation honest and they will match the way they look. Leave a loop early with Exit, which jumps straight past the Next. See also: For, To, Step, Each, Exit, Wend. |
; Next Example
; ------------
; Next closes the loop - execution jumps back to the For line
; until the counter passes its final value.
; Note: write plain Next, not Next stage - Blitz matches it automatically.
Print "Launch checklist:"
For stage=1 To 5
Print " Stage "+stage+" ... check!"
Next
Print ""
; Every For needs its own Next - nested loops need one each
Print "Search grid:"
For row=1 To 2
For col=1 To 3
Print " Scanning sector "+row+","+col
Next
Next
Print ""
Print "Press any key to close the example"
WaitKey
End