Do-while loop in Arduino


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 −

Updated on: 29-May-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements