case
variable [ anything1 [list-of-commands1] anything2 [list-of-commands2] ]
Parameters:
variable |
Variable |
variable to check |
[ anything1 [list-of-commands1] |
List of commands |
value to match and commands to run |
anything2 [list-of-commands2] ] |
List of commands |
value to match and commands to run |
Description:
Checks if the first argument
variable is equal to any of the anythings
in the list. If it is equal, the corresponding [list of commands]
is executed and control skips to the end of the case statement. A case statement can often be used in place of nested ifelse
statements. If nothing matches, no [lists of commands]
are executed and control skips to the end of the case statement. You can use true as one of your anythings as a default case.
Examples:
case energy
[
1 [setc blue]
2 [setc yellow]
3 [setc red]
true [setc white]
]
This command will set the turtle's color to blue if energy is 1, yellow if energy is 2, red if energy is 3 and white in any other case.
Notes:
The first input can be an expression as well as a variable.