2017-10-10 14:55:21 +00:00
|
|
|
[[ELSE]] is used in [[IF...THEN]] or [[SELECT CASE]] statements to offer an alternative to other conditional statements.
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
2017-10-10 14:55:21 +00:00
|
|
|
''Single-line syntax:''
|
|
|
|
: [[IF]] {{Parameter|condition}} [[THEN]] ''{code}'' [[ELSE]] ''{alternative-code}''
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
''Block syntax:''
|
|
|
|
: [[IF]] {{Parameter|condition}} [[THEN]]
|
|
|
|
:: ''{code}''
|
|
|
|
:: ⋮
|
|
|
|
: [[ELSEIF]] {{Parameter|condition2}} [[THEN]]
|
|
|
|
:: ''{code}''
|
|
|
|
:: ⋮
|
|
|
|
: [[ELSE]]
|
|
|
|
:: ''{alternative-code}''
|
|
|
|
:: ⋮
|
|
|
|
: [[END IF]]
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageDescription}}
|
|
|
|
* ELSE is used in a IF block statement to cover any remaining conditions not covered in the main block by IF or [[ELSEIF]].
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[CASE ELSE]] covers any remaining conditions not covered by the other CASE statements.
|
2017-10-10 14:55:21 +00:00
|
|
|
* ELSE can also be used as a false comparison to a true IF statement when a condition will only be true or false.
|
2015-08-02 12:12:44 +00:00
|
|
|
* Other [[IF...THEN]] statements can be inside of an ELSE statement.
|
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageExamples}}
|
2015-08-02 12:12:44 +00:00
|
|
|
''Example 1:'' One line IF statement
|
|
|
|
{{CodeStart}}
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
IF x = 100 THEN PRINT "100" ELSE PRINT "Not 100"
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
{{CodeEnd}}
|
|
|
|
|
|
|
|
''Example 2:'' Multiple line IF statement block
|
|
|
|
{{CodeStart}}
|
|
|
|
|
|
|
|
IF x = 100 THEN ' code executed MUST be on next statement line!
|
2019-04-15 01:15:33 +00:00
|
|
|
PRINT "100"
|
|
|
|
ELSE PRINT "Not 100"
|
2015-08-02 12:12:44 +00:00
|
|
|
END IF
|
|
|
|
|
|
|
|
{{CodeEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
''Example 3:'' To alternate between any two values (as long as the value after ELSE is the same as the condition)
|
|
|
|
{{CodeStart}}
|
|
|
|
|
|
|
|
IF a = 3 THEN a = 5 ELSE a = 3
|
|
|
|
|
|
|
|
{{CodeEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageSeeAlso}}
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[ELSEIF]]
|
|
|
|
* [[IF...THEN]]
|
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageNavigation}}
|