Lingo Dictionary > A-C > case |
![]() ![]() ![]() |
case
Syntax
case
expression
of
expression1
:Statement
expression2
:multipleStatements
. . .expression3
,expression4
: Statement {otherwise:statement(s)
} end case
Description
Keyword; starts a multiple branching logic structure that is easier to write than repeated if...then
statements.
Lingo compares the value in case expression
to the expressions in the lines beneath it, starting at the beginning and continuing through each line in order, until Lingo encounters an expression that matches case expression
.
When Lingo finds a matching expression, it executes the corresponding statement or statements that follow the colon after the matching expression. When only one statement follows the matching expression, the matching expression and its corresponding statement may appear on the same line. Multiple statements must appear on indented lines immediately below the matching expression.
When more than one possible match could cause Lingo to execute the same statements, the expressions must be separated by commas. (The syntax line containing expression3
and expresssion4
is an example of such a situation.)
After Lingo encounters the first match, it stops testing for additional matches.
If the optional otherwise
statement is included at the end of the case structure, the statements following otherwise
are executed if there are no matches.
If a case
statement tests cases that aren't all integer constants, the Export Xtra for Java converts the case
statement to an if...then
statement.
Example
The following handler tests which key the user pressed most recently and responds accordingly.
![]() |
If the user pressed A, the movie goes to the frame labeled Apple. |
![]() |
If the user pressed B or C, the movie performs the specified transition and then goes to the frame labeled Oranges. |
![]() |
If the user pressed any other key, the computer beeps. |
on keyDown case (the key) of "A": go to frame "Apple" "B", "C": puppetTransition 99 go to frame "Oranges" otherwise beep end case end keyDown
Example
This case
statement tests whether the cursor is over sprite 1, 2, or 3 and runs the corresponding Lingo if it is:
case the rollOver of 1: puppetSound "Horn" 2: puppetSound "Drum" 3: puppetSound "Bongos" end case
![]() ![]() ![]() |