What is the value of the variable result after the following code is executed?

count starts at 0 and number 2 is added to it at each iteration. The loop stops when count is equal or higher than 10. Therefore the values of count will be :

0, 2, 4, 6, 8, 10

These are all even numbers so count % 2 == 0 will be true.

result starts at 0 and at each iteration count is added to it. Therefore the final result will be the sum of all the above numbers. And

0 + 2 + 4 + 6 + 8 + 10 = 30

Leave a Comment