xxxxxxxxxx
//'i' can be any number
//Can be any comparison operater
//can be any number compared
//can be any mathmatic operater
for (int i = 0; i<100; i++){
//Do thing
}
//more info on operaters
//https://www.w3schools.com/cpp/cpp_operators.asp
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 < 5; i++)
{
cout << "Hello" << endl;
}
// prints hello 5 times.
xxxxxxxxxx
// i doesn't have to be defined as i, it could be any letter or word
// i < 10 means the code will loop 10 times before it ends
// i always starts at 0 unless you define it
// i++ means it increments by 1 every loop, can be any math function
for (int i; i<10; i++){
// Your code
}
// Great website to learn cpp: http://learn.onlinegdb.com/c%2B%2B_loops
xxxxxxxxxx
//I think this is a better way for a for loop
//for like going through arrays or something
//hope you like it :)
//be sure to do #include <set>
int main()
{
set<char> letters = {'A', 'B', 'C'};
for (auto itr = letters.begin(); itr != letters.end(); ++itr){
cout << *itr << endl;
}
}
xxxxxxxxxx
for (int i = start; i < stop; i = i + step){
// statement 1
// statement 2
// etc
}