IF...ELSEIF problem
Robert Schwartz
Posts: 141
I am currently working on a robotics project and I need to use an if elseif statement. The segemnt of code I am using is:
IF (Close_Right = 1) THEN CloseRight
ELSEIF (Close_Left = 1) THEN CloseLeft
ELSEIF (Far_Right = 1) THEN FarRight
ELSEIF (Far_Left = 1) THEN FarLeft
ELSE GiveUp
ENDIF
All of the variables are initialized and all of the labels have contents, but I get the error, "'ELSEIF' must be preceded by 'IF'" whenever I try to tokenize it. What is the matter with my syntax? Thank You.
IF (Close_Right = 1) THEN CloseRight
ELSEIF (Close_Left = 1) THEN CloseLeft
ELSEIF (Far_Right = 1) THEN FarRight
ELSEIF (Far_Left = 1) THEN FarLeft
ELSE GiveUp
ENDIF
All of the variables are initialized and all of the labels have contents, but I get the error, "'ELSEIF' must be preceded by 'IF'" whenever I try to tokenize it. What is the matter with my syntax? Thank You.
Comments
It doesn't take much more typing, and it does make the structure easier to read.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
It would appear as though this style is now enforced by the parser
IF (CloseRight=1) THEN CloseRight
is a 'single line version' of the IF statement -- the statement ends with the line-feed.
Thus:
IF (xyz) THEN GoToTarget
ELSEIF (abc) THEN GoToAnotherTarget
' The ELSEIF actually has no 'IF' in front of it,
' since the single-line IF is already done.
The equivalent for your code is:
IF (Close_Right = 1) THEN CloseRight
IF (Close_Left = 1) THEN CloseLeft
IF (Far_Right = 1) THEN FarRight
IF (Far_Left = 1) THEN FarLeft
GOTO GiveUp
Thus you don't need the ELSEIF construct -- it's already built into the code flow.