'alternative way to emulate FOR NEXT loop
' FOR NEXT syntax taken from QB64 wiki
'Description
'FOR...NEXT counter loops must be within the proper start, stop and
'increment values or the entire loop code block will not be executed.
'Avoid changing the FOR counterVariable's value inside of the loop.
' This obfuscates code and is a poor programming practice.
'Once the loop has been started, changing the variables holding
' the startValue, stopValue or increment value will not affect loop execution.
'If the STEP increment value does not match the startValue TO
'stopValue the FOR loop block will be ignored.
'If startValue is less than stopValue, use the default increment
'or positive STEP value or the loop will not be executed.
'If startValue is more than stopValue, use a negative STEP interval
'or the loop will not be executed.
'The STEP increment value cannot be changed inside of the loop.
'Use EXIT FOR to leave a FOR loop early when a certain condition
'is met inside of the loop.
'Use _CONTINUE to skip the remaining lines in the current iteration
'of a FOR/NEXT block without leaving the loop.
'The NEXT counter variable name is not required.
'NEXT loop increments can be separated by colons in nested FOR loops.
'NOTE: When the FOR loop is exited after the stopValue is reached,
' the counterVariables value will be stopValue + 1
'(or stopValue + increment)
'Beware of FOR loop counts that exceed the counterVariable type
'limits and may repeat without error in QB64.
'For example, if counterVariable is of type INTEGER and the stop
'limit exceeds 32767, the counterVariable will reset back to -32768
' and loop endlessly.
'Qbasic syntax
'FOR...NEXT Statement
'Repeats a block of statements a specified number of times.
'counter A numeric variable used as the loop counter.
'start and end The initial and final values of the counter.
'increment The amount the counter is changed each time through the loop.
min = 0
max = 1
steps = 1
whochange = 999
ForNext1 min, max, steps, whochange
min = 0
max = 1
steps = 1
whochange = 999
ForNext2 min, max, steps, whochange
min = 0
max = 0
steps = 1
whochange = 999
ForNext1 min, max, steps, whochange
min = 0
max = 0
steps = 1
whochange = 999
ForNext2 min, max, steps, whochange
' emulating For Next using Label + GOTO
whoChange = min
n = 0
NextAgain:
n = n + 1
Print "it runs "; n;
" times" whoChange = whoChange + steps
If whoChange
>= min
And whoChange
<= max
GoTo NextAgain
' emulating For Next using DO LOOP
whoChange = min
n = 0
n = n + 1
Print "it runs "; n;
" times" whoChange = whoChange + steps