0Pricing
C++ Academy · Lesson

Loop Patterns: for, while, do-while

Iterate with the three classic loop forms and pick the right one for the situation.

The for Loop

The classic indexed loop. Use it when you know how many iterations you need.

for (int i = 0; i < 10; ++i) {
    std::cout << i << " ";
}

Anatomy of a for Loop

Three parts separated by semicolons:

  • Init — runs once before the loop
  • Condition — checked before each iteration
  • Update — runs after each iteration

Any part can be empty.

All lessons in this course

  1. Branching: if-else, ternary, switch-case
  2. Loop Patterns: for, while, do-while
  3. Range-Based for Loop with Containers
  4. Early Returns break continue and goto
← Back to C++ Academy