C++ Infinite for Loop

When no parameters are given to the for loop, it repeats endlessly due to the lack of input parameters, making it a kind of infinite loop.

Example of Infinite for Loop

The below example demonstrates the use of multiple variables for loop in a C++ program.

C++




// C++ Program to demonstrate infinite loop
  
#include <iostream>
using namespace std;
  
int main()
{
    // skip Initialization, test and update conditions
    for (;;) {
        cout << "gfg" << endl;
    }
    // Return statement to show program compiles
    // successfully safely
    return 0;
}


Output

gfg
gfg
.
.
.
infinite times

for Loop in C++

In C++, for loop is an entry-controlled loop that is used to execute a block of code repeatedly for the specified range of values. Basically, for loop allows you to repeat a set of instructions for a specific number of iterations.

for loop is generally preferred over while and do-while loops in case the number of iterations is known beforehand.

Similar Reads

Syntax of for Loop

The syntax of for loop in C++ is shown below:...

Flowchart of for Loop in C++

Flowchart of for Loop in C++...

Examples of for Loop in C++

Example 1...

C++ Nested for Loop

...

Multiple Variables in for Loop

...

C++ Infinite for Loop

...

Range-Based for Loop in C++

A nested for loop is basically putting one loop inside another loop. Every time the outer loop runs, the inner loop runs all the way through. It’s a way to repeat tasks within tasks in your program....

for_each Loop in C++

...