Computer Science
Predict the output of the following code fragments:
x = 45
while x < 50 :
print (x)
Python
Python Control Flow
37 Likes
Answer
This is an endless (infinite) loop that will keep printing 45 continuously.
As the loop control variable x is not updated inside the loop neither there is any break statement inside the loop so it becomes an infinite loop.
Answered By
17 Likes
Related Questions
Predict the output of the following code fragments:
x = 10 y = 0 while x > y: print (x, y) x = x - 1 y = y + 1
Predict the output of the following code fragments:
keepgoing = True x=100 while keepgoing : print (x) x = x - 10 if x < 50 : keepgoing = False
Predict the output of the following code fragments:
for x in [1,2,3,4,5]: print (x)
Predict the output of the following code fragments:
for x in range(5): print (x)