/* 21/07/2021 switchv1 Basic use of the switch statement */ //An int is an integer, a Number, any value between -32,768 and 32,767 int q; int w; void setup() { // Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second Serial.begin(9600); //Send script name Serial.println("switchv1..."); //this will print a blank line Serial.println(" "); } void loop() { //q starts with a value of Zero, the loop continues while q smaller than 20 for (q = 0; q < 20; q++) { Serial.print("q: "); Serial.println(q); switch(q){ //q is equal to 1 case 1: Serial.println("q is equal to 1"); break; //q is equal to 2 case 2: Serial.println("q == 2"); break; //q is equal to a value we have not tested for default: Serial.println("q is not equal to 1 or 2"); break; } //the following if statements are all covered by the switch statement above /* if(q == 1){ } if(q == 2){ } if(q > 2){ } if(q<1){ } */ } //delay outside the for loop delay(100); }