Home / Programs / Infinite while loop Example 2
Programming Example

Infinite while loop Example 2

👁 1,082 Views
💻 Practical Program
📘 Step by Step Learning
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

Program Code

#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.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.