C++ Code
For Loop
#include <iostream>
#include<string>
int main
{
using namespace std;
int x;
for (x=0; x<10; x++)
cout << x << endl;
system ("pause");
return 0;
}
For Loop:
This will loop ten times (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), then stop when the statement x<10; is not longer true. Notice it did NOT say x<=10, so it will not print 10.
NOTE if you make x=1 instead of x=0 it will print (1, 2, 3, 4, 5, 6, 7, 8, 9) instead.
You can change the cout statement: cout << x << endl;
to: cout << "I will loop until the statement is no longer correct" << endl;
Go to While Loop