Counting Loops and the while Statement :

A counting loop is used when the number of times a loop must execute is known in
advance. The while statement is an entry-controlled repetition structure, which
means that the loop condition is tested before the loop body is executed.

If the condition is false initially, the loop body is not executed at all. The
while statement is commonly used for counting loops and for loops controlled by
a condition.
SYNTAX:

while (condition)
{
    statements;
}
EXAMPLE:

#include<stdio.h>

int main(){
    int x=1;
    while(x<3){
        printf("hi\n");
        x++;
    }
    return 0;
}

Output:

hi
hi
Previous Next