/* 21/07/2021 switchv3 Purpose, nesting a for loop in a 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("switchv3..."); //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){ case 1: Serial.println("q is equal to 1"); break; case 2: Serial.println("q == 2"); break; case 5 ... 10: Serial.println("value from 5 to 10"); //for(w=0;w<15;w++)...normal for loop //w takes on the value of q instead of 0 in the line above //this allows us to start our "for loop" at varying start values. for(w = q;w<15;w++){ Serial.print("w: "); Serial.println(w); } break; default: Serial.println("q is not equal to any tested case"); break; } } //delay outside the for loop delay(100); }