0

Explanation needed

int result = 0 for (int i = 0; i < 5; i++) { if i == 3 { result += 10 } else { result += i } } System.out.printIn(result); 17 Why result is 17 — could you explain please

13th Dec 2017, 9:49 AM
Alexander Salangin
Alexander Salangin - avatar
2 Answers
+ 1
i=0 else > res=0 i=1 else > res=1 i=2 else > res=3 i=3 if > res =13 i=4 else > res = 17 end += adds right value to left.
13th Dec 2017, 9:56 AM
Dima Makieiev
Dima Makieiev - avatar
+ 1
Thanx!
13th Dec 2017, 10:36 AM
Alexander Salangin
Alexander Salangin - avatar