Program problem
Ken Lyons
Posts: 15
When I try to load a particular program it reports the error "for" without "next" but next is clearly there and this at the last of a number of steps with for and next.
Help!
Help!
Comments
The FOR / NEXT relationship is dynamic in that the NEXT doesn't have to follow the FOR in the text of the program, but it has to follow in the flow of control of the program. If you give a variable name after the NEXT, it has to match the FOR variable.
FOR x = 1 TO 15
left = left + 1 MAX lstop
right = right - 1 MIN rstop
GOSUB p_out
The FOR gets highlighted and then the message says For without NEXT.
Do you need the whole thing or is this enough?
The FOR goes at the beginning of the loop and specifies the variable to be used and the starting and ending values of that variable. The NEXT marks the end of the loop.
NEXT
FOR x = 1 TO 15
left = left - 1 MIN lmin
right = right - 1 MIN rmin
GOSUB p_out
NEXT
FOR x = 1 TO 15
left = left + 1 MAX lstop
right = right + 1 MAX rstop
GOSUB p_out
NEXT
FOR x = 1 TO 9
left = left - 1 MIN lmin
right = right + 1 MAX rmax
GOSUB p_out
NEXT
FOR x = 1 TO 15
left = left + 1 MAX lstop
right = right - 1 MIN rstop
GOSUB p_out
The last "FOR" gets highlighted and triggers the error message. How come only that one?
For some reason you have an orphan NEXT beginning the code segment. It's in the wrong place. Put it at the end of the code segment.