Complete the code to declare the state variable.
int state = [1];The initial state is usually set to 0 to start the state machine.
Complete the switch statement to check the current state.
switch([1]) { case 0: // do something break; case 1: // do something else break; }
The switch statement should check the current state variable to decide the action.
Fix the error in the state update line.
case 0: // transition to state 1 state [1] 1; break;
Use the assignment operator '=' to update the state variable.
Fill both blanks to complete the state machine loop and switch.
while([1]) { switch([2]) { case 0: // do something state = 1; break; case 1: // do something else state = 0; break; } }
The loop runs while true (1), and the switch uses the state variable.
Fill all three blanks to add a default case and update the state machine.
switch(state) {
case 0:
// action for state 0
state = [1];
break;
case 1:
// action for state 1
state = [2];
break;
default:
// reset state
state = [3];
break;
}State 0 transitions to 1, state 1 transitions back to 0, and default resets to 0.
