How to loop a set number of times?

How can I loop a statement a number of times?

aka

1
2
3
4
5
6
7
int loopnumber

Loop statment int number of times {

my looped info goes here

}


How would I do this?
Use a for loop.
http://cplusplus.com/doc/tutorial/control/#for

Enjoy!

EDIT: Dangit.

-Albatross
Last edited on
I cant under stand how to use it. Can you explain how I'd do it?
Did you look at the example?
1
2
3
for(int i = START_VALUE; i < END_VALUE; ++i) {
    // looped info
}
1
2
3
4
5
6
7
8
9
10
11
//An example taken from the page on the for loop
#include <iostream>
using namespace std;
int main ()
{
  for (int n=10; n>0; n--) {
    cout << n << ", ";
  }
  cout << "FIRE!\n";
  return 0;
}
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE!


EDIT: Dangit again.

-Albatross

Last edited on
Ok, but what I'm trying to do is loop it a variable number of times:

1
2
3
4
5
6
7
int loopthismany

loop(loopthismany) {

//looped info

}
Nobody ever said that END_VALUE in Zhuge's example had to be a constant. It could just as easily be a variable or a return value from a function. :)

-Albatross
Topic archived. No new replies allowed.