PBP IF statement nesting question


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2008
    Location
    Monrovia, AL
    Posts
    7

    Default PBP IF statement nesting question

    PBP version: 2.45A

    I'm failing to see something obvious, apparently.

    The intended behavior of the following code fragment is that the ELSE should associate with the first indented IF. Instead, it is being associated with the first non-indented IF.

    IF fsmState = idleSt THEN
    IF kpLastValue != kpValue THEN
    hserout[CR, LF, "***DEBUG - idleSt, br: mainMenuSt ", CR, LF]
    kpLastValue = kpValue
    fsmNextState = mainMenuSt
    ENDIF
    ELSE
    hserout[CR, LF, "***DEBUG - drawIdle check ", CR, LF]
    IF sec != lineSecondsLast THEN
    gosub drawIdle
    lineSecondsLast = sec
    lineMinutesLast = minute
    lineHoursLast = hour
    lineDayLast = day
    lineMonthLast = month
    lineYearLast = year
    lineCenturyLast = century
    ENDIF
    ENDIF

    How does one formulate the syntax to achieve the desired behavior?

    Thanks-Dan

  2. #2
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    i read this quickly but think this is what u want , remove the commented endif

    also try use code encapsulated when adding code to post ,

    cheers


    Code:
    IF fsmState = idleSt THEN
        IF kpLastValue != kpValue THEN
           hserout[CR, LF, "***DEBUG - idleSt, br: mainMenuSt ", CR, LF]
           kpLastValue = kpValue
           fsmNextState = mainMenuSt
          ' Remove this   ENDIF i think 
        ELSE
           hserout[CR, LF, "***DEBUG - drawIdle check ", CR, LF]
     
            IF sec != lineSecondsLast THEN
                 gosub drawIdle
                 lineSecondsLast = sec
                 lineMinutesLast = minute
                 lineHoursLast = hour
                 lineDayLast = day
                 lineMonthLast = month
                 lineYearLast = year
                 lineCenturyLast = century
            ENDIF
    
       ENDIF
    
    ENDIF

  3. #3
    Join Date
    Nov 2008
    Location
    Monrovia, AL
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    I appreciate the help with this.

    If I comment out the ENDIF suggested, the compiler returns an error, "IF without a matching ENDIF" . There appears to be no way to make the first inner IF multi-statement. Is the ELSE broke in this situation?

    Sorry about the non-encapsulated code segment.

    Thanks-Dan

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


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    Did you add the third ENDIF at the end after commenting out the first?

    And this code editor really helps in this situation
    http://www.picbasic.co.uk/forum/cont...75-FineLineIDE
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    Try IF kpLastValue <> kpValue THEN instead of IF kpLastValue != kpValue THEN, because the IF/then/else/Endif structure seems correct.

    Cheers

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Nov 2008
    Location
    Monrovia, AL
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    Quote Originally Posted by mackrackit View Post
    Did you add the third ENDIF at the end after commenting out the first?
    No. I missed that.
    Moving the ENDIF appears to work. I guess I'm too used to languages (verilog, etc.) that have a way of explicitly-delineating blocks of statements.

    Thank you for the help!

    -Dan

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


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    that have a way of explicitly-delineating blocks of statements
    That is where FineLine helps.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Nov 2008
    Location
    Monrovia, AL
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: PBP IF statement nesting question

    Quote Originally Posted by mackrackit View Post
    That is where FineLine helps.
    I'll certainly give FineLine a shot.
    Thanks-Dan

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