//'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
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
// just example for explanation :)
// vector containt strings
vector<string> USERS;
// take string from 'USERS'
// under name 'user' in each time :)
for(string user : USERS){
std::cout << user << std::endl;
}
//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;
}
}
for ( init; condition; increment ) {
statement(s);
}
Example:
for ( i=0; i<5; i++ ) {
cout<<"Hello World"<<endl; //Hello World is going to be print out 5 times
}
// 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
// REMEMBER TO REPLACE '???'
// with the data structure to iterate on
for(int i=0; i<???; ++i) {}
for(auto it=???.begin(); it!=???.end(); ++it) {}
for(auto &obj : ???) {}
#define FOR(x,a,b) for(int x = a; x <= b; x++)
#define FOD(x,a,b) for(int x = a; x >= b; x--)
#define REP(x,a,b) for(int x = a; x < b; x++)
#define RED(x,a,b) for(int x = a; x > b; x--)