Question Detail
Question
Examine the following code snippet from Slide 11:
What will happen when this code runs?
num = 10
while num > 0:
print(num)
num = num + 1What will happen when this code runs?
Correct Answer
Option C is the correct answer.
Detailed Explanation
The variable
num starts at 10. The condition num > 0 is True. Inside the loop, num is incremented (num = num + 1), so it will become 11, 12, etc., always remaining greater than 0. Thus, the condition will never become False, leading to an infinite loop.
Hint
Pay close attention to how the `num` variable is updated inside the loop.