For Loops

In this example, we use two assignments in the first part separated by commas. We also have two statements to execute at the end of the loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//for loop prints by .5 
#include <iostream>
using namespace std;
int main() { 
  double num; //used to 'drive' the loop
  int count;
  for (num = 0, count=0; num<11; num+=0.2,count++) { 
    cout<<num;
    if(count%5==0) cout<<endl;
    else cout<<"\t";
  } //for loop
  cout<<endl;
  system("pause");
  return 0;
} //main
CODE

output

What other number sequences can you print?

NEXT: Compare for and while