int num;
void setup() {
Serial.begin(9600);
}
void loop() {
num = 2;
switch (num) {
case 1:
Serial.println("One");
break;
case 2:
Serial.println("Two");
break;
case 3:
Serial.println("Three");
break;
default:
Serial.println("Default");
}
delay(2000);
}
/*In this example, "Two" will be printed to the serial monitor because num
is equal to 2. If num were 1 or 3, the corresponding case would be executed.
If num doesn't match any of the cases,
the code in the default block will be executed.
The break statement is used to exit the switch statement.
Without it, the execution would "fall through" to subsequent cases,
which might lead to unintended behavior.
*/