ELSE: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "ELSE is used in IF...THEN or SELECT CASE statements to offer an alternative to other conditional statements. {{PageSyntax}} ''Single-line syntax:'' : IF {{Parameter|condition}} THEN ''{code}'' ELSE ''{alternative-code}'' ''Block syntax:'' : IF {{Parameter|condition}} THEN :: ''{code}'' :: ⋮ : ELSEIF {{Parameter|condition2}} THEN :: ''{code}'' :: ⋮ : ELSE :: ''{alternative-code}'' :: ⋮ : END IF {{PageDescription}...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 54: | Line 54: | ||
{{PageSeeAlso}} | |||
{{PageSeeAlso}} | |||
* [[ELSEIF]] | * [[ELSEIF]] | ||
* [[IF...THEN]] | * [[IF...THEN]] |
Latest revision as of 00:31, 29 January 2023
ELSE is used in IF...THEN or SELECT CASE statements to offer an alternative to other conditional statements.
Syntax
Single-line syntax:
Block syntax:
Description
- ELSE is used in a IF block statement to cover any remaining conditions not covered in the main block by IF or ELSEIF.
- CASE ELSE covers any remaining conditions not covered by the other CASE statements.
- ELSE can also be used as a false comparison to a true IF statement when a condition will only be true or false.
- Other IF...THEN statements can be inside of an ELSE statement.
Examples
Example 1: One line IF statement
IF x = 100 THEN PRINT "100" ELSE PRINT "Not 100" |
Example 2: Multiple line IF statement block
IF x = 100 THEN ' code executed MUST be on next statement line! PRINT "100" ELSE PRINT "Not 100" END IF |
Example 3: To alternate between any two values (as long as the value after ELSE is the same as the condition)
IF a = 3 THEN a = 5 ELSE a = 3 |
See also