+ 4
I want someone to explain to me why output 17
int result=0; for (int I=0;I<5;I++) if(I==3) result +=10; else result +=I; why output =17
5 Respostas
+ 8
it's correct
I = 0 result = 0 + 0
I = 1 result = 0 + 1
I = 2 result = 1 + 2
I = 3 result = 3 + 10
I = 4 result = 13 + 4 = 17
why are you expecting something else?
+ 7
The loop runs for values of l = 0,1,2,3,4. When I is 3, add 10 to result. For all other values of l which is not 3, add the value of l.
0 + 1 + 2 + 10 + 4
17
+ 6
0+1+2+10+4=17
+ 2
Thank you guys
+ 1
Were you trying to exit the loop after 10 is added to the result 🤨?