- Name:
- else
- Syntax:
-
IF condition THEN
{code}
ELSEIF condition THEN
{code}
ELSE
{code}
ENDIFSELECT CASE variable
CASE condition
{code}
ELSE
{code}
ENDSELECTCondition - The condition which will cause the associated code commands to be executed or not.
Code - Command statements which will be executed dependant upon the evaluation of the condition. These command statements may include further single line and multi-line 'if' commands. This is commonly known as having 'nested if statements'.
- Description:
-
The else command is used as part of a multiple line if...then \ else \ endif command and part of a multiple lineseelct case \ case \ else \ endselect command.
IF condition THEN
{code}
ELSE
{code}
END IF
A multi-line or block-structured 'if' command is spread over multiple lines. When the condition evaluates as true the code between the 'if condition then' and 'else' commands is executed, otherwise the code between the 'else' and 'end if' command is executed. After either sets of code are executed program execution will continue on the line after the 'end if'.For more detailed information and further examples, please see the if command page.
IF condition THEN
{code}
ELSEIF condition THEN
{code}
ELSE
{code}
END IFInstead of an 'else' command it is possible to use an 'elseif' command and specify another condition. If the first condition is true the code between the 'if condition then' and 'elseif condition then' command will be executed, otherwise the 'elseif' condition will be evaluated, and, if true, the code between 'elseif condition then' and 'end if' will be executed.
An 'else' command can be added to an 'if' and 'elseif' command sequence which will be executed if no previous 'if condition then' or 'elseif conditon then' has evaluated as true.For more detailed information and further examples, please see the if command page.
SELECT CASE variable
CASE condition
{code}
ELSE
{code}
ENDSELECTWhere an 'else' command is used in a 'select case' command and no 'case' conditions have been met then the code associated with the 'else' command will be executed. The code associated with the 'else' condition is only executed when no other condition has been met so it is a 'catch-all' for all other 'select case' variable values which do not match any explicit 'case' conditions.
For more detailed information and further examples, please see the select case command page.
Flash an LED when a button is pressed
Continually check C.0 to see if it is high - if it is, turn B.1 on for 5 seconds
- Code Example:
-
main: if pinC.0 = 1 then goto flsh ; jump to flsh if pin0 is high else goto main ; else loop back to start end if flsh: high B.1 ; switch on output B.1 pause 5000 ; wait 5 seconds low B.1 ; switch off output B.1 goto main ; loop back to start
Copy Code Submit an Example
Submit Your Own Code!
You must be logged in to submit code examples. Login now.