The Infinite While Loop in Python

WhAt is the output of this puzzle?


while True:


The question in this puzzle is whether the second print statement will ever be executed. The body of the while loop consists of the pass statement. This statement tells the interpreter to do nothing. Although the while loop does nothing, the interpreter is trapped forever because the while condition is True. Thus, our program wastes scarce CPU cycles until the user interrupts the execution. Hence, no execution path will execute the second print statement. It is interesting that 60 percent of Finxters do this wrong.

Are you a master coder?
Test your skills now!

Related Video




Leave a Comment

Your email address will not be published. Required fields are marked *