Skip to reading
BASIC Scripting

Choose a response with IF

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

THE BASIC LANGUAGE

Evaluate the most specific condition first. Once a condition succeeds, BASIC runs that branch and skips the rest.

Code example
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
Source table from Choose a response with IF, page 10
coins = 1The first comparison succeeds. The answer is “Too few coins.”
coins = 2The first comparison fails. ELSEIF catches the exact amount.
coins = 3Both 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.

Page 10 of 86Permalink
Go to page