Programming Example
Infinite while loop Example 1
Example of infinite while loop
#include <stdio.h>
int main()
{
int var = 6;
while (var >=5)
{
printf("%d \n", var);
var++;
}
return 0;
}
51232
51233
51234
51235
51236
51237
51238
51239
51240
51241
........
........
........
infinite time
value >=5 so the loop would never end. 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.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.