🟡 Control Flow  ·  Lesson 17

for Loop in C++

for Loop in C++

What is for Loop in C++?

for Loop in C++
A for loop repeats a block when the number of repetitions is known or controlled by a counter.
Level
🟡 Control Flow and Core Programming
Example File
for-loop.cpp
Main Focus
Concept + syntax + practical C++ program

Why should you learn this?

  • It helps you write correct and readable C++ programs.
  • It is used repeatedly in school practicals, projects and competitive programming.
  • It builds the base for advanced topics such as OOP, STL and data structures.

Important Terms

TermMeaning / Use
initializationInitialization used in for Loop in C++ programming.
conditionCondition used in for Loop in C++ programming.
updateUpdate used in for Loop in C++ programming.
iterationIteration used in for Loop in C++ programming.
counterCounter used in for Loop in C++ programming.

Syntax / Pattern

for(initialization; condition; update) { statements; }

Example Program

#include <iostream>
using namespace std;
int main(){
    for(int i=1; i<=5; i++){
        cout << i << " ";
    }
    return 0;
}

Expected Output

1 2 3 4 5

Program Explanation

  • i starts from 1.
  • Loop runs while i <= 5.
  • i++ increases counter after each iteration.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • tables
  • patterns
  • array traversal

Common Mistakes

  • Creating infinite loops.
  • Wrong start/end condition.

Practice Tasks

  1. Print table of 7.
  2. Print first 10 natural numbers.

Summary

for Loop in C++ is an important C++ topic. Learn the definition, understand the syntax, run the example program and then solve the practice tasks to make the concept strong.

What is for Loop in C++?

for Loop in C++
A for loop repeats a block when the number of repetitions is known or controlled by a counter.
Level
🟡 Control Flow and Core Programming
Example File
for-loop.cpp
Main Focus
Concept + syntax + practical C++ program

Why should you learn this?

  • It helps you write correct and readable C++ programs.
  • It is used repeatedly in school practicals, projects and competitive programming.
  • It builds the base for advanced topics such as OOP, STL and data structures.

Important Terms

TermMeaning / Use
initializationInitialization used in for Loop in C++ programming.
conditionCondition used in for Loop in C++ programming.
updateUpdate used in for Loop in C++ programming.
iterationIteration used in for Loop in C++ programming.
counterCounter used in for Loop in C++ programming.

Syntax / Pattern

for(initialization; condition; update) { statements; }

Example Program

#include <iostream>
using namespace std;
int main(){
    for(int i=1; i<=5; i++){
        cout << i << " ";
    }
    return 0;
}

Expected Output

1 2 3 4 5

Program Explanation

  • i starts from 1.
  • Loop runs while i <= 5.
  • i++ increases counter after each iteration.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • tables
  • patterns
  • array traversal

Common Mistakes

  • Creating infinite loops.
  • Wrong start/end condition.

Practice Tasks

  1. Print table of 7.
  2. Print first 10 natural numbers.

Summary

for Loop in C++ is an important C++ topic. Learn the definition, understand the syntax, run the example program and then solve the practice tasks to make the concept strong.

← Back to C++ Tutorial