If...then...else


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    25

    Default If...then...else

    Why do I get a Syntax Error for the ELSE row?

    loop2:
    ADCIN 0, involt 'Read channel 0 to involt
    PAUSE 100 'Wait 100 ms
    IF involt >= 128 THEN GPIO.5 = 0
    ELSE GPIO.5 = 1 ENDIF
    GOTO loop2
    END

    PIC12F683 & PBP2.60

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    ELSE likes to be on a line of it's own.
    Try

    Code:
    loop2: 
    ADCIN 0, involt 'Read channel 0 to involt
    PAUSE 100 'Wait 100 ms
    IF involt >= 128 THEN GPIO.5 = 0 
    ELSE 
    GPIO.5 = 1 
    ENDIF
    GOTO loop2
    END
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    ELSE likes to be on a line of it's own.
    No, didn't help:

    ERROR Line 30: ELSE without a matching IF..THEN. (ADC1.pbp)
    ERROR Line 32: ENDIF without a matching IF..THEN. (ADC1.pbp)

    That would suggest that they should all be on the same row, but that was my first attempt.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by mikebike View Post
    No, didn't help:

    ERROR Line 30: ELSE without a matching IF..THEN. (ADC1.pbp)
    ERROR Line 32: ENDIF without a matching IF..THEN. (ADC1.pbp)

    That would suggest that they should all be on the same row, but that was my first attempt.
    Code:
    loop2: 
    ADCIN 0, involt 'Read channel 0 to involt
    PAUSE 100 'Wait 100 ms
    
    IF involt >= 128 THEN 
      GPIO.5 = 0 
    ELSE 
      GPIO.5 = 1 
    ENDIF
    
    GOTO loop2
    END
    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks, that worked. But why?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    IF xxx THEN label
    can be on one line because it act as a GOTO.
    If not a label the THEN needs to be on a second line.
    YUP, I messed up on my first post. Was not paying attention...
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post
    Thanks, that worked. But why?
    simply because the compiler considers there's no need for ELSE nor ENDIF, if he sees anything on the right side of THEN ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 0

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