Table of Contents
Introduction
Now, what if we skip the condition part of our loops and run our code without any condition? There comes the case of the infinite loop in C.
There occur some loops that can repeat infinite times. These are called infinite loops.
This happens when we do not write a condition to check true/false, and by default, whatever is initialised, propagate accordingly infinitely because their condition is always true.
Example
#include<stdio.h> int main() { int x; for(x=1; ;x++) { printf("infinite"); } return 0; }
Output
Explanation
So just write the code in your text editor, and you will get the same messed up output as shown.
This happens because the condition part is empty in the ‘for’ loop, and the value of ‘x’ is repeatedly increasing, and every time the condition is true, which gives a never ending-output.
Terminate an infinite loop in C
To terminate an infinite loop, press ctrl+c. The display will come back to your code editor screen.
0 Comments