xxxxxxxxxx
// infinite for loop
for(int i = 1; i > 0; i++) {
// block of code
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 20; i++)
{
cout << i << endl;
}
//prints the number (i)
}
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
for (/* init var */;/* break condition */;/* mathmatic operation */) {
// do something
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
for (int i=0;i<5;i++)
cout << i <<endl;
}