//'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;
}
}
#include <iostream>
using namespace std;
int main(){
for(int i=1; i<=6; i++){
/* This statement would be executed
* repeatedly until the condition
* i<=6 returns false.
*/
cout<<"Value of variable i is: "<<i<<endl;
}
return 0;
}
// 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 : ???) {}