♦ C++ For Loop
♣ About C++ For Loop
The For Loop in C++ can be used to iterate over a condition for a constraint with desired incremental/decremental rate.♣ C++ For Loop Syntax
For loop accepts three statements as arguments.Below is the representation of C++ For Loop Syntax.
Basic Syntax
for (statement_1; statement_2; statement_3) { // code for execution }
Syntax Explanation:
statement_1 : initialization statement statement_2 : constraint statement statement_3 : increment statement
♣ Example1: Square number Iteration in C++
In this example, square of numbers will be printed till 10. Example
Input:
Output:
♣ Example2: Calculating Factorial with For Loop in C++
In this example, Factorial of 6 will be calculated using For Loop. Example
Input:
Output: