Home C Programming Language / Programs / Infinite while loop Example 2
🚀 Programming Example

Infinite while loop Example 2

👁 1,085 Views
💻 Practical Program
📘 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);
     }
}
                        

🖥 Program 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.
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.