Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/StateMachines1
- Timestamp:
- Nov 6, 2019, 11:50:07 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/StateMachines1
v1 v2 34 34 }}} 35 35 36 This program introduces a new type of variable called an enumeration ('''enum'''). An enum is a variable that can hold one of the values you specify when you declare it. For example: {{{ enum Color { RED, GREEN, BLUE }; }}} In this example, we've enumerated the states the robot can be in: starting, driving forward, turning, and stopped. 36 This program introduces a new type of variable called an enumeration ('''enum'''). An enum is a variable that can hold one of the values you specify when you declare it. For example: 37 {{{ enum Color { RED, GREEN, BLUE }; }}} 38 In this example, we've enumerated the states the robot can be in: starting, driving forward, turning, and stopped. 37 39 38 40 The program also introduces the '''switch''' statement which is another type of conditional like ''if ,else if, else''. With a switch statement, the condition is the value of a variable; execution jumps to the ''case'' that matches the variable's value and proceeds forward from there until a ''break'' statement is encountered which exits the switch block. If there is no case statement matching the variable's value, the '''default''' case is executed.