Infinite loop in C
An infinite loop is one that does not terminate the loop from its looping condition. An infinite loop can be needed in programming in some special conditions or some loop can fall into infinite loops when the exit condition becomes false forever.
Infinite for loop in C
For loop has a condition to terminate the loop. This condition can be left as blank. We can also skip initialization statement and repeat statements. These are optional and can be left as blank.
Infinite while loop in C
While loop While loop has a condition statement. This expression is mandatory and cannot be skipped. So we need to place a true condition here. We can place “TRUE”, “1”, “1==1” etc any of the statement.
Infinite do-while loop in C
Do While loop While loop has a condition like while loop. We can make place the same always true statement to make an infinite loop.
Long running loops
It is recommended to put some delay in each loop. Otherwise task may take up all CPU cycles and may hang up the system. This is needed if programmer is polling for some condition to happen. A sleep statement will release the task to scheduler and other task will be able to run properly.
Debug infinite loops
A program can enter into an infinite loop and the program can loop forever. This type of issue may not happen very often and some rare situations can bring this type of condition. However, these types of issues are easy to debug. We should break in a statement and put the break in the condition check. We need to find out why the condition is not becoming false to root cause further.
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average