What is an infinite loop?

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

Infinite For Loop:

for(;;){
//code to be executed
}
Infinite While Loop:

while(1){
//code to be executed
}
Infinite Do-While Loop:

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

An infinite loop is a programming construct where a sequence of instructions repeats indefinitely, without a terminating condition. In other words, the loop continues endlessly until it’s manually interrupted or until the program is halted. This situation can arise unintentionally in a program, causing it to become unresponsive or to consume excessive system resources. Infinite loops are often considered errors in programming unless intentionally used for specific purposes, such as in real-time systems or when creating programs that are designed to run continuously without termination. In C, an example of an infinite loop could be:

c

#include <stdio.h>

int main() {
while (1) {
printf(“This is an infinite loop.\n”);
}
return 0;
}

In this example, the condition 1 is always true, so the loop will continue executing indefinitely.