please assist with how this code computes to get the 17 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

please assist with how this code computes to get the 17

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

15th May 2019, 9:26 AM
Jabu Sibiya
Jabu Sibiya - avatar
3 Answers
+ 3
When the condition is false values of i includes 0,1,2,4 therefore result is 7 but when it's true the value of result is now 10 + 7 which is 17
15th May 2019, 10:09 AM
Alabo Gift
Alabo Gift - avatar
0
It is computed step by step (sequential), evaluating each expression and execute the statement for each line of code.
15th May 2019, 10:48 AM
Daniel Adam
Daniel Adam - avatar