Do-while loop in Arduino

ArduinoArduino BoardsArduino IDEArduino Programming Language

The do-while loop’s syntax in Arduino is similar to the syntax in C. It is given below −

do{
   //Code
} while (condition);

Note the semicolon at the end.

Example

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   Serial.println();

   int i = 5;
   do{
      Serial.println(i);
      i--;
   } while(i > 0);

}

void loop() {
   // put your main code here, to run repeatedly:
}

Output

The Serial Monitor output is shown below −

raja
Published on 29-May-2021 13:53:43
Advertisements