For Loops

In this example, we count by 5's. Notice the n+=5 as the last part of the for loop

1
2
3
4
5
6
7
8
9
10
11
//for loop prints 5 10 15 20 25 30 35 40 45
#include <iostream>
using namespace std;
void main() { 
  int n; //used to 'drive' the loop
  for(n=5; n<50; n+=5) { //count by 5
    cout<<n<<"\t"; //tab instead of \n after each number
  } //for loop
  cout<<endl; //end the line that just had tabs
  system("pause");
} //main
CODE
output

You should be able to use a for loop to display any sequence of values.

NEXT: Multiply to generate power of 2