PDA

View Full Version : PBP IF statement nesting question



lurker
- 15th September 2012, 03:29
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

longpole001
- 15th September 2012, 04:07
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




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

lurker
- 15th September 2012, 04:46
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

mackrackit
- 15th September 2012, 06:27
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/content.php?r=275-FineLineIDE

aratti
- 15th September 2012, 08:18
Try IF kpLastValue <> kpValue THEN instead of IF kpLastValue != kpValue THEN, because the IF/then/else/Endif structure seems correct.

Cheers

Al.

lurker
- 15th September 2012, 14:48
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

mackrackit
- 15th September 2012, 15:36
that have a way of explicitly-delineating blocks of statements

That is where FineLine helps.

lurker
- 15th September 2012, 22:03
That is where FineLine helps.
I'll certainly give FineLine a shot.
Thanks-Dan