What is an infinite loop?

C Programming Language >   Loop control in C Language >   Loop Introduction in C  

Long Question

736


Answer:

A loop running continuously for an indefinite number of times is called the infinite loop.

An infinite loop in C language is a loop that continues to execute indefinitely, without any exit condition. It is created by using a logical condition that is always true, such as "1==1" or "i > 0". For example, the following code snippet creates an infinite loop:

Infinite For Loop:


for(;;){  
//code to be executed  
}  

It can also be created by ommiting the exit condition of the loop.


for(int i=0; ; i++){
   // code that runs indefinitely
}

Infinite while Loop:


while(1){  
//code to be executed  
}  

Infinite Do-While Loop:


do{  
//code to be executed  
}while(1);  

It is important to be careful when using infinite loops, as they can cause the program to crash or freeze if not designed properly.


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.