For Loop
The for loop is more complex than the other loops and consists of three parts. Structure of for loop:
for (counter; exit condition; loop expression)
{
// block of instruction
do_something;
}
- Counter;
- Exit condition;
- Loop expression.
main.cpp
123456789#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
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.85
For Loop
Swipe to show menu
The for loop is more complex than the other loops and consists of three parts. Structure of for loop:
for (counter; exit condition; loop expression)
{
// block of instruction
do_something;
}
- Counter;
- Exit condition;
- Loop expression.
main.cpp
123456789#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