Infinite while loop Example 2

C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)

993

Program:

#include <stdio.h>
int main()
{
     int var=1;
     while (var <=2)
     {
        printf("%d \n", var);
     }
}

Output:

1
1
1
1
1
1
1
1
1
......
......
.....
infinite time
 

Explanation:

The program is an example of infinite while loop. Since the value of the variable var is same (there is no ++ or – operator used on this variable, inside the body of loop) the condition var<=2 will be true forever and the loop would never terminate.

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.