Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
For Loop | Introduction to Program Flow
C++ Introduction
course content

Course Content

C++ Introduction

C++ Introduction

1. Getting Started
2. Variables and Data Types
3. Introduction to Operators
4. Introduction to Program Flow
5. Introduction to Functions

bookFor 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.
cpp

main

copy
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 the counter variable to mark the passage of the loop;
  • counter <= 5: loop termination condition. The loop will continue if the counter variable is less than or equal to 5.
How many iterations will this loop make?

How many iterations will this loop make?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 6
some-alt