C++ for statement

C++ for loop statement

The for statement has three expressions, semicolon are used for separating these expressions. so the syntax of statement is

for(expression1; expression2; expression3)
{
statement
statement
………
………
………
}

In the for loop body statement can be single or group of statements

In this above example Expression1 is initialization expression, expression2 is condition expression and in the last expression3 is an update expression. in the for loop, expression1 is executed only once when the loop start then initialize the loop variables.This expression is know as initialize or assignment expression because its initialize the value.expression2 is condition and its tested or check condition at every iteration of the loop, so this condition expression generally uses logical and relational operators. At the end expression3 is an update expression and its execute every time after execute the body of the loop.

for loop in c++

/* program to understand the concept of for loop*/
#include <iostream>
int main()
{
int i;
for(i=0;i<=10;i++)
{
std::cout<<"C++ program";
}
return 0;
}

/* program to print 1 to 100 number using for loop*/
#include <iostream>
int main()
{
int i;
for(i=1;i<=100;i++)
{
std::cout<<i;

}
return 0;
}

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise