4.4.7 Switch/Case/Default
On [Switch] page, you can create multiple switches, and control the flow of the program according to the value of the variables. You can set whether to add a Default
program block to the program tree. For "Synchronize", see the description of "Synchronize" in "4.3.6 Assignment".
You can use the [Case] command to create a Case
program block under Switch
.
Case
node can be inserted under Switch
node only. Application
Switch...Case...Default...
: Execute differentCase
program blocks by determining the conditions. You can enter the selection and determination condition expression in theSwitch
interface, and enter the matching value in theCase
interface. When the program runs theSwitch
node, it first calculates the value of the expression of theSwitch
node, which is then compared with the values of theCase
under theSwitch
: If the same value is matched in all the conditions, theCase
program block will be executed; if no matchingCase
value is found, the "Default" program block under thatSwitch
will be executed.- A
Switch
can include 0 to severalCase
program blocks. - A
Switch
can include 0 to 1 "Default" program block, which can be added by checking the "Add Default " in theSwitch
.
- A
Example:
Set an initial variable var_0. Access the program and run it to
Waypoint_0
. Determine whether var_0
is equal to 0. If var_0
is equal to 0, run MoveJ
with the comment "Right"; If var_0
is not equal to 0, determine whether var_0
is equal to 1. If var_0
is equal to 1, run MoveJ
with the comment "Left". If var_0
is neither equal to 0 nor equal to 1, run MoveJ
with the comment "High".