Home / Programs / Infinite while loop Example 3
Programming Example

Infinite while loop Example 3

👁 1,012 Views
💻 Practical Program
📘 Step by Step Learning
Infinite loop: var value will keep decreasing because of –- operator, hence it will always be <= 10.

Program Code

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

Output

-15563
-15564
-15565
-15566
-15567
-15568
-15569
 ...........
............
............
..........
infinite time
 

Explanation

Infinite loop: var value will keep decreasing because of –- operator, hence it will always be <= 10.

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.