#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
for(int i = 0; i < 10; i++) // A basic for loop
{
cout << "Number: "<< i << endl; // Display myNumber
}
getchar(); // wait for a key to be pressed
return 0;
}
/*
Learn how to use a for loop.
Use a for loop when the number of repetitions is known.
Let us take a closer look at our for loop:
----------------------------------------------------------------
for(int i = 0; i < 10; i++)
{
cout << i;
}
----------------------------------------------------------------
for - for loop
int i = 0 - create a new integer i, start counting at 0
i < 10 - if i is larger than 10, then stop the for loop
i++ - i=i+1; increase i with 1
{ - start the foor loop
cout << i; - print out i
} - go to next i (if i < 10 then end the for loop)
----------------------------------------------------------------
Description:
The for loop loops from the given start walue to the given stop value.
The amount of loops will then be stop - start.
In this case the for loop will loope 10 times (10 - 0).
Since the start count is 0 the last count will be 9.
----------------------------------------------------------------
*/
Download Visual C++ Source Code
I hope you found this c++ tutorial useful!
Don't forget to mention Apron Tutorials in your References!