If then, else if, then ...
hyperlinear
Posts: 4
Every time I try to use this command, the syntax checker ALWAYS says "Expected A Label" right after the first THEN ... ???? Below is the code example as given in the help section of the editor and IT DOESN'T WORK EITHER. What gives here? I'm using a BS2p stamp. (Pardon me if this has been addressed somewhere else, as the search terms "IF", "THEN", "ELSEIF", etc. seem "too common" words for the forum search engine.)
value VAR Word
Main:
DO
PULSIN 0, 1, value ' measure pulse input
DEBUG DEC value, CR
IF (value > 4000) THEN ' evaluate duration
DEBUG "Value was greater than 4000"
ELSEIF (value = 4000) THEN
DEBUG "Value was equal to 4000"
ELSE
DEBUG "Value was less than 4000"
ENDIF
DEBUG CR, CR
PAUSE 1000
LOOP
value VAR Word
Main:
DO
PULSIN 0, 1, value ' measure pulse input
DEBUG DEC value, CR
IF (value > 4000) THEN ' evaluate duration
DEBUG "Value was greater than 4000"
ELSEIF (value = 4000) THEN
DEBUG "Value was equal to 4000"
ELSE
DEBUG "Value was less than 4000"
ENDIF
DEBUG CR, CR
PAUSE 1000
LOOP
Comments
According to the Stamp documentation, this command is supported in PBasic 2.5.
Have you declared that at the top of your code?
***************************************
...rats! Mr. Savage beat me to it!!!
Thanks!
In PBASIC 2.0:
IF (condition) THEN label ' The program will execute the code starting at label if the condition is met.
Adding this line will stop that error:
' {PBASIC 2.5} ' This is a compiler directive telling the compiler to use PBASIC 2.5
Well, I'm not sure about that requirement...I mean any code examples we have that require that directive to be there should have it in the example code itself. So if you're copying the code from something it should match the source exactly or this can happen.
Well Sir, it depends at which "example" one is looking.
There are what I call the "snippets" of examples on the main discussion page of any command, and then there are the example pages.
The main discussion page presumes (not "assumes" ) the information at the top of the page has been read and understood, so the snippets then make sense. The full example pages have all required code.
It appears that the OP copied the snippet only.