Ask coding questions

← Back to all posts
How
GarretThyCarrot (30)

How to make code forever in python and the stop when user says

Thanks

Answered by Bookie0 (3930) [earned 5 cycles]
View Answer
Commentshotnewtop
Bookie0 (3930)

Well you can do a while True loop so that it loops forever, then do use an if statement to determine when the user says to stop, and then use break

Happy coding and hope this helps! =)

GarretThyCarrot (30)

@Bookie0 oh ok and then how with the if?

Bookie0 (3930)

just do

while True:
  # code here to be run forever
  stop = input("press 1 to stop")
  
  if stop == "1":
    break

@GarretThyCarrot

GarretThyCarrot (30)

Ok thank you so much for replying! Your ver fast @Bookie0

Bookie0 (3930)

sure (i'm fast bc im a lot on repl.it ask section ;) @GarretThyCarrot