Python 2 looping a program back to the begining

2 posts
by Casper2017 » Fri May 19, 2017 10:20 am

After writing a program, how is it possible to have it loop back to the beginning.

All examples on the web show how to use loops, but that is with numbers.

I would just like the program to loop back to the beginning of the program.

Posts: 18
Joined: Thu Mar 23, 2017 12:44 pm
by ghans » Fri May 19, 2017 10:23 am
Code: Select all
import sys

while True:
      # loop everything inside this block forever
      print "Loop"
   except KeyboardInterrupt:
      # ... or at least until we want to abort via Ctrl-C as usual under Linux

Your whole program can be one while loop. Its a common idiom.

• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere
Posts: 7207
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany