Correct option is D
The loop in option
(d), while 1 % 1:, will
not run an infinite number of times.
Here's why:
·
1 % 1 evaluates to 0 because the remainder when dividing 1 by 1 is 0.
· In Python, any value that evaluates to 0 is considered
False in a Boolean context.
· Since 0 is
False, the loop will not execute, and the print("ALWAYS") statement will not be run.
Important Key Points:
1.
while loop: The condition in a while loop is checked before each iteration. If the condition evaluates to
True, the loop runs; if it evaluates to
False, the loop stops.
2.
1 % 1 = 0: Since the modulus operation results in 0, the condition evaluates to
False, causing the loop to terminate immediately.
3.
Other Loops: In the other options:
·
while 21 % 2: will always return 1 (True), as 21 is an odd number.
·
while 21 // 2: will return 10 (True), as the floor division of 21 by 2 is 10.
·
while True: will run infinitely because True is always true.
Knowledge Booster:
·
Option (a):
while 21 % 2: will run infinitely because 21 % 2 results in 1 (which is evaluated as True), so the condition remains true.
·
Option (b):
while 21 // 2: will run infinitely because 21 // 2 results in 10 (which is evaluated as True), so the condition remains true.
·
Option (c):
while True: will run infinitely because True always evaluates as true.