Course Content
C++ Introduction
C++ Introduction
2. Introduction to Operators
4. Introduction to Program Flow
5. Introduction to Functions
For Loop
The for loop is more complex than the other loops and consists of three parts. Structure of for loop:
- Counter;
- Exit condition;
- Loop expression.
main
#include <iostream> int main() { for (int counter = 0; counter <= 5; counter++) { std::cout << counter << std::endl; } }
int counter = 0
: iteration counter;counter++
: 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.
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 5