0
for(a=0;a<50;a+=10) in the first iteration a=0 hence 0=10 is the case why are'nt we writing the output from 10.I am a beginner n
2 Answers
+ 2
The Tutorial says:
"for (init, condition, increment)"
"The init step is executed first, and does not repeat.
Next, the condition is evaluated, and the body of the loop is executed if the condition is true.
In the next step, the increment statement updates the loop control variable.
Then, the loop's body repeats itself, only stopping when the condition becomes false.
"
+ 2
Here are the steps:
1. a=0 // a is set to 0, only happens once
2. a<50 // checks condition
3. cout << a // prints a, I assume that's what is in your code block
4. a+=10 // increments a then back to step 2
So a is 0 when it is first printed and then incremnts to 10.
Final output is: 0 10 20 30 40