0
Can someone explain this code?
3 Answers
+ 1
Hello Even Dead I Am The Hero.
At first you need to enter a number for n. Let's say 5.
Then you have a while loop. While i <= n. The loop runs until i gets larger than 5.
i starts at 1 and sum at 0.
1 <= 5
sum += 1 //1
i += 1 //2
2 <= 5
sum += 2 //3
i += 1 //3
3 <= 5
sum += 3 //6
i += 1 //4
4 <= 5
sum += 4 //10
i += 1 //5
5 <= 5
sum += 5 //15
i += 1 //6
6 <= 5 is false, end while loop
print 15.
+ 1
Denise Roberg thank you so much for this explanation.
0
Even Dead I Am The Hero.
Your welcome :)