0
CODE BREAKDOWN
can someone breakdown this code please. I dont understand how result = 17. int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);
4 Antworten
+ 13
● code run for i=0, 1, 2, 3, 4 .
//adding each value of i to result & when i==3 add 10 instead of 3, answer by Jay Matthews sir make it clear
+ 10
i=0;
In first itration if (i==3) false
else => result+=i; result = 0;
i=1;
In second itration if (i==3) false
else => result+=i; result = 1;
i=2;
In third itration if (i==3) false
else => result+=i; result = 3;
i=3;
In forth itration
if (i==3) result += 10; result = 13;
i=4;
In fifth itration if (i==3) false
else => result+=i; result = 17;
0
Thank you guys
0
d