A For Loop is a repetitive statement that is used to check for some condition and then based upon the condition a block of code is executed repeatedly until the specified condition is satisfied.
The for loop is distinguished from other looping statements through an explicit loop counter or loop variable which allows the body of the loop to know the exact sequencing of each iteration.
Hence a for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
Next the condition is evaluated. If it holds true, the body of the loop is executed. If it holds false, the body of the loop does not execute and flow of control jumps to the next iteration(repetition of a process).
You will often see an increment operation as the update statement (e.g. i++, count++). This is often seen as one of the distinguishing features and possible name sources for the C++ language.
The body of the for loop need not be enclosed in braces if the loop iterates over only one satatement.
##Example
```c++
#include<iostream.h>
using namespace std;
int main () {
// Single line for loop
for( int a = 10; a <20;a =a+1)
cout << "value of a: " <<a<<endl;
return 0;
}```
This would generate the same output as the previous program.
i.e
Output:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
```
## Explanation
Here's the initialization condition is first set to a=10. The loop first checks for this condition. It then checks for the condition expression i.e a<20whichholdstrueas10<20(forthefirstcase).Nowthebodyoftheloopisexecutedandwegettheoutput"Valueofa:10".Thentheupdateexpressionisexecutedwhichaddsthenumber1to'a'andthevalueof'a'getsupdatedto11andthesamestepsarefollowed(asabove)untilthevalueofvreacheslessthan20i.e19.
# Range-based for-loop
C++ also has what we call range-based for loops which iterates through all the elements of a container(e.g. array).