typos, grammar, output fixes (#22987)

Minor fixes to typos, grammar and example output framing
This commit is contained in:
Matt
2018-11-20 19:00:47 -05:00
committed by Manish Giri
parent 65c5b03a41
commit d219d38644

View File

@ -2,11 +2,12 @@
title: For Loop
---
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.
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.
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.
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.
For loop is an entry controlled loop unlike do-while loop.
@ -44,17 +45,19 @@ Note that the variables declared in init can only be used inside the brackets of
### condition
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).
### update
The update statement is used to alter the loop variable by using simple operations like addition, subtraction, multiplication or division.
The update statement executes after the execution of the body of the loop.
### increment
The increment statement is used to alter the loop variable by using simple increment operations and executes after the completion of the body of the loop.
### update
The update statement is used to alter the loop variable by using simple operations like addition, subtraction, multiplication or division and executes after the execution of the body of the loop.
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.
## IMPLEMENTATION:
```C++
#include <iostream>
using namespace std; // Here we use the scope resolution operator to define the scope of the standar functions as std::
using namespace std; // Here we use the scope resolution operator to define the scope of the standard functions as std::
int main () {
// for loop execution
@ -63,8 +66,10 @@ int main () {
}
return 0;
}```
}
```
```
Output:
value of a: 10
value of a: 11
@ -76,6 +81,7 @@ value of a: 16
value of a: 17
value of a: 18
value of a: 19
```
##Single lined loop
The body of the for loop need not be enclosed in braces if the loop iterates over only one satatement.
@ -91,10 +97,10 @@ The body of the for loop need not be enclosed in braces if the loop iterates ove
return 0;
}```
}
```
This would generate the same output as the previous program.
i.e
```
Output:
value of a: 10
value of a: 11