0

I don't understand the for loop in c++

The for loop (c++)

22nd Apr 2017, 9:21 PM
kawan azizi
kawan azizi - avatar
4 odpowiedzi
+ 9
for (counter; condition; incrementation) counter is what allows the loop to know what position it is in, let it be some variable. (Often, and integer). for(int i = 0;;) Condition is a boolean statement that allows the loop to run if the condition is true. for(int i = 0; true;) the incrementation is what change you are making to the counter. This is called everytime the loop finishes. for(int i = 0; true; i=i+1) { // code in loop } explained: i starts at 0. the condition is true, so execute what's inside the loop. Everytime the loop reaches the end, increase i by 1, check condition, if true keep going. in practice: for(int i = 0; i < 10; i++) { //block to execute in cout << i; } output: 0123456789
22nd Apr 2017, 11:14 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
it's simply. for ( //first go a some var you must declare it and give some value // int i = 0 ; // next go condiction loop will go so far as the condiction is true// i<2; // next is incrementation of our var ( or decrementation i--)// i++)
22nd Apr 2017, 10:13 PM
MKey
MKey - avatar
+ 2
what are you don't understood ?
22nd Apr 2017, 10:06 PM
MKey
MKey - avatar
+ 2
example : for ( int i=0; i<2; i++) { do some things } that loop will go for two times
22nd Apr 2017, 10:17 PM
MKey
MKey - avatar