Latest Posts:

The for loop in c++

The for loop


The "for loop" loops starting with one number then onto the next number and increments by a predetermined value each time.

syntax 
for (Start value; end condition; increase value)
      statement(s);

example

#include<iostream>
 using namespace std;

 int main()
 {
  int a;

  for (a= 0; a < 10; a++)
  {
   cout << "for loop in c++" << "\n";
   cout << "is very easy" << "\n";
  }
  return 0;
 }

Note that:
a solitary direction can be set behind the "for loop" without the wavy sections.
How about we take a gander at the "for loop" from the illustration: We initially begin by setting the variable a to 0. This is the place we begin to tally. At that point, we say that the for loop must run if the counter m is littler than ten. Last we say that each loop a should be expanded by one (a++).

In the case, we utilized a++ which is the same as utilizing a  =a + a. This is called increasing. The direction a++ adds 1 to a. On the off chance that you need to subtract 1 from a  you can utilize a– . It is additionally conceivable to utilize ++a or - a. The distinction is that with ++a the one is added to the "for loop" tests on the off chance that a < 10. With a++ the one is included after the test a < 10.
Share on Google Plus

About Lucky Ibitubo

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Powered by Blogger.