Shop OBEX P1 Docs P2 Docs Learn Events
Program problem — Parallax Forums

Program problem

Ken  LyonsKen Lyons Posts: 15
edited 2010-11-28 06:38 in BASIC Stamp
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!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-27 11:40
    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.
  • Ken  LyonsKen Lyons Posts: 15
    edited 2010-11-27 12:59
    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.

    Do you need the whole thing or is this enough?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-11-27 13:17
    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.
  • Ken  LyonsKen Lyons Posts: 15
    edited 2010-11-28 05:22
    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?
  • stamptrolstamptrol Posts: 1,731
    edited 2010-11-28 05:38
    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.
  • Ken  LyonsKen Lyons Posts: 15
    edited 2010-11-28 06:38
    Thanks guys. Syntax now OK.
Sign In or Register to comment.