1 3 5
Just after "5" is printed, the NEXT ODD
statement will
change ODD
from 5 to 7.
But 7 is GREATER THAN
the ending value 5, so the loop ends.
Here is the program with a picture of how it works.
The numbers under "time" show the changing values in ODD
.
time --> FOR ODD = 1 TO 5 STEP 2 1 3 5 7 <-- exceeds the limit, 5, PRINT ODD; 1 3 5 so the loop stops NEXT ODD 3 5 7 ' END
This is a little bit confusing.
Notice that ODD
starts out at 1
and counts up by two.
At the end, the NEXT ODD
ODD
to 7,
but when this happens the loop
is exited because 7 is GREATER THAN the endingValue 5.
Here is a new version of the program (the endingValue has been changed). What does this program print?
FOR ODD = 1 TO 9 STEP 2 PRINT ODD; NEXT ODD ' END