+ 2

Anyone tell me how the output become 17 ??

int result=0; for(int i=0; i<5;i++){ if(i==3){ result+=10; }else { result+=i; } }

11th Dec 2017, 1:31 PM
MUʜAMMED ÉȘʟʟYAS
MUʜAMMED ÉȘʟʟYAS - avatar
3 Answers
+ 4
first loop result = 0+0= 0 second loop result = 0+1=1 third loop result = 1+2=3 fourth loop result = 3+10=13 fifth and final loop result = 13+4=17
11th Dec 2017, 1:36 PM
TheLegend27
TheLegend27 - avatar
+ 2
@TheLegend27 thnxxxx😊😊😊
11th Dec 2017, 1:42 PM
MUʜAMMED ÉȘʟʟYAS
MUʜAMMED ÉȘʟʟYAS - avatar
+ 2
when (i=0,1,2,or 4) we use "result=result+I" when (i=3) we use "result=result+10" i=0 » result=0+0=0 i=1 » result=0+1=1 i=2 » result =1+2=3 (*) i=3 » result =3+10=13 i=4 » result =13+4=17 👍
11th Dec 2017, 1:48 PM
Ahmed Mohammed Ahmed Khodary
Ahmed Mohammed Ahmed Khodary - avatar