C++ for loops - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Saturday 7 October 2017

C++ for loops

C++ for loops



C++ for loops is very similar to a while loops in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line. for loop is an entry-controlledloop.
The basic format of for loop statement is:
Syntax:
for ( init; condition; increment )
{
   statement(s);
}
Figure – Flowchart of for loop:
cplusplus-for

Example of a C++ Program to Demonstrate for loop

 Example:
#include <iostream>
using namespace std;

int main ()
{
   /* local variable Initialization */
   int n = 1,times=5;

   /* for loops execution */
   for( n = 1; n <= times; n = n + 1 )
   {
      cout << "C++ for loops: " << n <<endl;
   }
   return 0;
}
Program Output:
cplusplus-for-loops

No comments:

Post a Comment

Post Top Ad