Course Content
Introduction to C++
For Loop
The for loop is more complex than the other loops and consists of three parts:
- Counter;
- Exit condition;
- Loop expression.
Structure of for loop:
For example:
main.cpp
int counter = 0
– iteration counter;counter++
is the same ascounter = counter + 1
;
For each iteration, 1 will be added to thecounter
variable to mark the passage of the loop;counter <= 5
– loop termination condition. The loop will continue if thecounter
variable is less than or equal to 5.
Loops are convenient to use with arrays:
main.cpp
In this case, we used one loop to initialize all 10 array elements and a second loop to display the array elements.
How many iterations will this loop make?
Select the correct answer
Section 4.
Chapter 6