Syntax of while loop

    increment or decrement;
    // statements

initialization: An initial value is assigned to a variable in this section.
condition: Condition is checked and statements are executed inside while loop if condition is true.
increment or decrements:  Update initial value to count number of iteration and based on the update value condition will be false and loop will stop.


int main()
    int i;
        printf("Iteration %d\n",i);
    return 0;


Iteration 1
Iteration 2
Iteration 3
Iteration 4

If you don’t understand how this while loop works then read for loop first.

Next Previous