0
I have doubt in the below code, I have attached my questions in the code as comments.
4 odpowiedzi
+ 1
for(initialization ; condition_check; update) {
//loop body..
}
first Initialization happens, then condition is checked, if true loop body executed otherwise don't, in next step it updates values, next it goes to check again condition..
This gets repeated until condition false.
I=I*i = 3*3=> 9
Next step is upadate i before checking condition so i += 3 => 9+3=12
Hope it clears...
+ 1
It's a for loop, now 3 * 3 = 9 but in the for loop as specified it has to run 5 times so it's just constantly multiplying
0
Jayakrishna🇮🇳 then why doesn't it happen the same way in for(int i=0;i<5;i+=3)
0
Do you mean 0 output?
Because int i=0 ; creates a local variable in for loop block, it shadows outside global i. And local i variable does not exist outside loop.
So out side, loop i unmodified by loop. So value 0 remains.. Outputs 0;
Hope it clears..