/* 21/07/2021 forLoopv2 Purpose, to see different versions of the for loop code */ //An int is an integer, a Number, any value between -32,768 and 32,767 int q; void setup() { // Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second Serial.begin(9600); //Send script name Serial.println("forLoopv2..."); //this will print a blank line Serial.println(" "); } void loop() { //Example 1 Serial.print("Example 1"); //q starts with a value of Zero, the loop continues while q smaller than 20 for(q=0;q<20;q++){ //print the value of q to the serial monitor Serial.print("Val q: "); Serial.println(q); //delay within the for loop delay(100); } //delay outside the for loop delay(1000); //example 2 Serial.print("Example 2"); for(q=30;q<40;q++){ //print the value of q to the serial monitor Serial.print("Val q: "); Serial.println(q); //delay within the for loop delay(100); } //delay outside the for loop delay(1000); //example 3 Serial.print("Example 3"); //q is reducing in value through the loop //q-- subtracts 1 from the value of q for(q=50;q>35;q--){ //print the value of q to the serial monitor Serial.print("Val q: "); Serial.println(q); //delay within the for loop delay(100); } //delay outside the for loop delay(1000); //example 4 Serial.print("Example 4"); //q is reducing in value through the loop //q-- subtracts 1 from the value of q //displays q going negative for(q=10;q>-10;q--){ //print the value of q to the serial monitor Serial.print("Val q: "); Serial.println(q); //delay within the for loop delay(100); } //delay outside the for loop delay(1000); }