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.
Contact Us