Home / Programs / Infinite while loop Example 1
Programming Example

Infinite while loop Example 1

👁 1,243 Views
💻 Practical Program
📘 Step by Step Learning
Example of infinite while loop

Program Code

#include <stdio.h>
int main()
{
     int var = 6;
     while (var >=5)
     {
        printf("%d \n", var);
        var++;
     }
   return 0;
}

Output

51232
51233
51234
51235
51236
51237
51238
51239
51240
51241
........
........
........
infinite time

Explanation

Infinite loop: var will always have value >=5 so the loop would never end.

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.