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 differentCaseprogram blocks by determining the conditions. You can enter the selection and determination condition expression in theSwitchinterface, and enter the matching value in theCaseinterface. When the program runs theSwitchnode, it first calculates the value of the expression of theSwitchnode, which is then compared with the values of theCaseunder theSwitch: If the same value is matched in all the conditions, theCaseprogram block will be executed; if no matchingCasevalue is found, the "Default" program block under thatSwitchwill be executed.- A
Switchcan include 0 to severalCaseprogram blocks. - A
Switchcan 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".