FOR..NEXT Loop Bug?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    3

    Default FOR..NEXT Loop Bug?

    I've had a problem with the FOR..NEXT loop in a couple of projects in the past and it just happened again. I thought this time I would see if it's something I'm doing or a problem with the compiler. Basically I'm using a FOR..NEXT loop to initialize some data in a serially connected Amulet LCD touch screen.

    The FOR..NEXT loop which does not work is as follows:

    FOR i = 32 to i = 37
    addVar = i
    GOSUB SetByte
    Next i

    SetByte:
    SEROUT2 tr,84,[$D5,hex2 addVar,hex2 TByte]
    SERIN2 rx,84,500,SetByte,[In[0]]
    IF In[0] <> $F0 then SetByte
    Return

    The above code will not work. However the code below will properly set the Amulet variables.

    addVar = 32
    GOSUB SetByte
    addVar = 33
    GOSUB SetByte
    addVar = 34
    GOSUB SetByte
    AddVar = 35
    GOSUB SetByte
    addVar = 36
    GOSUB SetByte
    addVar = 37
    GOSUB SetByte

    Any insight would be appreciated. For now I'm avoiding using FOR..NEXT loops.

    Thank You
    Mike

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: FOR..NEXT Loop Bug?

    Hi Mike,

    The syntax is ...

    FOR i = 32 to 37
    DT

  3. #3
    Join Date
    Jun 2006
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: FOR..NEXT Loop Bug?

    Thank you Darrel, dumping the i= does correct the problem. I don't do much programing in basic, primarily in c and java. I guess I need to pay a bit more attention. Just one question shouldn't the compiler throw a syntax error? With the improper syntax it compiles without error.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: FOR..NEXT Loop Bug?

    Quote Originally Posted by MSapper View Post
    Just one question shouldn't the compiler throw a syntax error? With the improper syntax it compiles without error.
    Well no ..., What you had wasn't "Invalid Syntax". In fact it was quite legal.
    It just didn't make sense for what you wanted to do.

    Logical operators return numbers that can be interpreted as True or False, but those numbers can be used for other purposes as well.
    It's up to the programmer to determine when they are appropriate.

    If it threw an error, some ingenious person would find a valid use for a logical operator in a FOR loop, and they'd be really ticked off when it didn't work.
    DT

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts