xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 20; i++)
{
cout << i << endl;
}
//prints the number (i)
}
xxxxxxxxxx
// infinite for loop
for(int i = 1; i > 0; i++) {
// block of code
}
xxxxxxxxxx
for ( int i = 0; i < 5; i++)
{
cout << "Hello" << endl;
}
// prints hello 5 times.
xxxxxxxxxx
for (int i = start; i < stop; i = i + step){
// statement 1
// statement 2
// etc
}
xxxxxxxxxx
for (int i = 0; i < 10; i++){
//Do something as long as i is less than 10,
//In that case it will loop 10 times
//use break; to restart the loop whenever you want to cancel the loops.
cout << i;
//at the end, remember i will be increased by 1.
}
//output 0123456789
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
for (int i=0;i<5;i++)
cout << i <<endl;
}
xxxxxxxxxx
//limit can be any number
//you can use any comparison operator
for(int iteration = 0; iteration < limit_number; iteration++)
{
//action in for loop
}