Loops are used to execute a block of statements repeatedly. The statement which is to be repeated will be executed n times inside the loop until the given condition is reached. There are two types of loops Entry controlled and Exit-controlled loops in the C programming language. An Infinite loop is a piece of code that lacks a functional exit. So, it repeats indefinitely. There can be only two things when there is an infinite loop in the program. One it was designed to loop endlessly until the condition is met within the loop. Another can be wrong or unsatisfied break conditions in the program.
Types of Loops
Below is the program for infinite loop in C:
C
#include <stdio.h>
int main()
{
for (;;) {
printf ( "Infinite-loop\n" );
}
while (1) {
printf ( "Infinite-loop\n" );
}
do {
printf ( "Infinite-loop\n" );
} while (1);
return 0;
}
|