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 THENIF 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
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
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
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
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.
Re: PBP IF statement nesting question
Quote:
Originally Posted by
mackrackit
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
Re: PBP IF statement nesting question
Quote:
that have a way of explicitly-delineating blocks of statements
That is where FineLine helps.
Re: PBP IF statement nesting question
Quote:
Originally Posted by
mackrackit
That is where FineLine helps.
I'll certainly give FineLine a shot.
Thanks-Dan