For loop in c++ with example

For loop is another loop in c++

Syntax:-

for(initialization; condition; increment)
{
Body of the loop
}
Statement;

Note:-

# If body of loop is only one statement than braces ({}) are not needed.
# Body of the loop may have one or more statement.
# Initialization and increment can be skip but semicolon should be there to separate 3 section.
# Condition section can`t be skip in for loop.

Execution:-

In for loop 1st variable is initialized than condition will check if condition is true than body of the loop will executed. After body of the loop is execute, variable is incremented and the condition is again tested if condition is true than again body of loop is executed, this process is repeated until condition is true. When condition is false than statement next to while loop is executed.

For loop can be written in another way by skipping initialization and increment condition.

Syntax:-

Initialization;
for( ; condition; )
{
Body of the loop
Increment;
}

Variable can be declared in for loop

Example:-

for(int i=0; i < num; i++) Example:-

Program to count N numbers



Program to display N even number



Previous Code:-
Conditional operator

List Code:-
C++ Codes

Next Code:-
While loop

C++ Programs
List of c++ Programs

7 Comments

  1. help meeeeee plase
    By using ioop, display 85to 80,75to70....user will rnter range??

    ReplyDelete
    Replies
    1. Burger, the answer is always burger ....
      sometimes Fries.
      did you know im half french
      half fries

      Delete
  2. You want me to display like this 85to 80,75to70,65 to 60,55 to 50

    ReplyDelete
  3. superb!!!!! This really helped me ..........

    ReplyDelete
  4. if you enter 25, the program will display even numbers all the way until 26 then loop terminates.

    ReplyDelete

Add your comments here

Back to Top