Infinite Loops in C
0 354
Infinite loops in C are when your program gets stuck doing the same thing over and over again forever.
It is like a broken record that keeps on playing the same song without stopping.
This happens when you forget to give the loop a way to know when it stops, so it just keeps going endlessly.
It is important to avoid infinite loops because they can make your program freeze or crash.
We can use any type of loop in it like a while loop, for loop, and many more.
Infinite loop in C Explanation
Syntax of Infinite loop in C
while(condition){In this syntax, the loop keeps executing until the condition remains True.If the condition never becomes false the loop becomes infinite.
// loop body
}
Example:
#include<stdio.h>In this example, condition 1 is always true, so the loop runs indefinitely, printing "Infinite loop is executed" over and over again.
int main()
{
while(1){
printf("Infinite loop is executed\n");
}
return 0;
}
Share:
Comments
Waiting for your comments