Can anyone explain why the outcome of this for lope is "5"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone explain why the outcome of this for lope is "5"?

int outcome = 5; for (int i = -3; i < 4; i += 2){ outcome = outcome - i; } System.out.println(outcome);

29th Aug 2020, 10:19 PM
Flex
1 Answer
+ 4
outcome =5 I = - 3 outcome =outcome - i ; => 5 - -3 = 8 i = i +2 = - 3 +2 =-1 Outcome = 8 - -1 = 8+1=9 i = - 1 +2 = 1 Outcome = 9 - 1 =8 i = 1 +2 =3 Outcome = 8 - 3 = 5 I = 3 +2 =5 and i<4 condition fails so outcome value is 5 finally...
29th Aug 2020, 10:25 PM
Jayakrishna 🇮🇳