in C Plus Plus by
What are loops and how can we create an infinite loop in C?

1 Answer

0 votes
by

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

Types of Loops

 Below is the program for infinite loop in C:

C

// C program for infinite loop
// using for, while, do-while
#include <stdio.h>
  
// Driver code
int main()
{
    for (;;) {
        printf("Infinite-loop\n");
    }
  
    while (1) {
        printf("Infinite-loop\n");
    }
  
    do {
        printf("Infinite-loop\n");
    } while (1);
  
    return 0;
}
...