QUESTION IMAGE
Question
quiz 3 - loops
the code below was rejected by a lead programmer:
n = 0
while (n < 10)
display(\woo\)
n = n - 1
why do you think this code was rejected?
The code has a logical error in the increment operation. In the line n = n - 1, instead of incrementing n (which is needed to eventually exit the loop when n < 10 is no longer true), it is decrementing n. So the loop will either run infinitely (if the language allows n to go into negative values without bounds) or until some system - imposed limit on negative values is reached, and will not achieve the likely intended goal of looping 10 times.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The n = n - 1 statement decrements n instead of incrementing it, which may lead to an infinite loop or incorrect loop behavior.