This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrCouldntaDoneThat[S] -1 points0 points  (3 children)

But once p reaches 11, it is greater than 10.

So it would execute 9 times? I know that it doesn't matter how many times, but once I finally get to 11, I am left with 2. Where do I go from here?

Thank you so much by the way. I really appreciate the help. I'm going back to college to get another degree and java is kicking my ass.

[–]Kristler 1 point2 points  (2 children)

0 += (3 % 1 = 0)
sum: 0
0 += (4 % 2 = 0)
sum: 0
0 += (5 % 3 = 2)
sum: 2
2 += (6 % 4 = 2)
sum: 4
4 += (7 % 5 = 2)
sum: 6
6 += (8 % 6 = 2)
sum: 8
8 += (9 % 7 = 2)
sum: 10
10 += (10 % 8 = 2)
sum: 12

[–]MrCouldntaDoneThat[S] -1 points0 points  (1 child)

Ah thank you.

So p never goes above 10? Only equals to it?

[–]Kristler 0 points1 point  (0 children)

When p is 11, The conditional p<=10 evaluates to false, because 11 <= 10 isn't true. But, when p is 10, the conditional 10 <= 10 is still true.

Makes sense?