0
I don't understand the for loop in c++
The for loop (c++)
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
+ 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++)
+ 2
what are you don't understood ?
+ 2
example :
for ( int i=0; i<2; i++) { do some things }
that loop will go for two times