For loop in C++

by Nideesh C on May 7, 2011 · 0 comments

in C++




A for loop is said to be very handy and is used very often inside a program. Because it is easy to represent and debug for errors. This loop is used when we know the number of repetitions.

Syntax:

for(<initialization>;<condition>;<increment/decrement>)

{

Statements;

.

.

}

/*————————————————————*/

//To display odd values between 1 and 10

#include<iostream.h>

#include<conio.h>

void main()

{

int oddval;

for(oddval=1;oddval<=10;oddval+=2)

cout<<oddval<<endl;

getch();

}

Output:

1

3

5

7

9

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. While loop in C++
  2. Do…while loop in C++
  3. C program to find the sum of first 50 natural numbers using for loop
  4. Java program – While loop
  5. C program to evaluate the given polynomial P(x)=AnXn + An-1Xn-1 + An-2Xn-2+… +A1X + A0, by reading its coefficients into an array. [Hint:Rewrite the polynomial as P(x) = a0 + x(a1+x(a2+x(a3+x(a4+x(...x(an-1+xan)))) and evaluate the function starting from the inner loop]

Leave a Comment

Previous post:

Next post: