Account
Categories

Infinite do-while loop


Infinite do-while loop:

Infinite do-while loop

At the beginning of this loop, the code executes once. Then it checks the condition. If the condition is right, the code will run infinitely. The loop will only exit when a break statement is given inside it.

Syntax:

do {
    // statements
} while (condition);

Example:

#include <stdio.h>
int main() {
    int i = 1;
    do {
        printf("First loop\n");
        i++;   
    } while (1);   
    return 0;
}

Output:

First loop
First loop