Choose a response with IF
THE BASIC LANGUAGE
Evaluate the most specific condition first. Once a condition succeeds, BASIC runs that branch and skips the rest.
FUNCTION Run()
DIM coins = 3
IF coins < 2 THEN
RETURN "Too few coins."
ELSEIF coins = 2 THEN
RETURN "Exact fare."
ELSE
RETURN "Change due."
END IF
END FUNCTION| coins = 1 | The first comparison succeeds. The answer is “Too few coins.” |
|---|---|
| coins = 2 | The first comparison fails. ELSEIF catches the exact amount. |
| coins = 3 | Both comparisons fail. ELSE handles the remaining case and returns “Change due.” |
Close a multiline IF with END IF. ELSEIF is one word. An ELSE is optional when the script has nothing to do for the remaining case.
