void setup() {Serial.begin(9600); //begin serial communication }
void loop() { for(int i=0;i<10;i++){ . //loop from 0 to 9 Serial.print(" i is "); Serial.println(i); //print i delay(200);}delay(1000);
for(int i=9;i>=0;i--){ . //loop from 9 to 0 Serial.print(" i is "); Serial.println(i); //print i delay(200);}delay(1000);
}
'while' loop
int switchValue, i;
void setup() { Serial.begin(9600);}
void loop() { switchValue=digitalRead(10); //digital read a switch
while(switchValue==1){ //loop through while the switch is on Serial.print("The switch is on, and i is "); Serial.println(i); //print i delay(200); i++; //add one to i switchValue=digitalRead(10); //read the switch again before repeating loop }
i=0; //reset i back to zero Serial.print("The switch is off, and i is ");Serial.println(i);delay(50); }