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!
Please show your program. If it's small, you can cut and paste and use the "#" tags around your code so you don't lose the formatting. If it's large, use the paper clip icon to attach your program file to your message.
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.
NEXT
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.
In your case, you need the NEXT to come at the end of the loop. I assume that's after the GOSUB.
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.
Thanks for getting back to me so quickly. Too, if this was easy then everyone would do it or so I tell myself. In any event the following is the entire sequence of steps:
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?
As Mike pointed out, FOR begins a loop and NEXT ends it. Your last FOR loop has no corresponding NEXT.
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.
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.