Search code examples
pythonfor-loopwhile-loopinfinite-loopdo-loops

While loop and For loop together


Hi I want to run make for loop to run infinitely.

for eg.

while True:

    try:
     script()

except Exception as e:
        script()
        continue

as below because in For loop I have lists where i want to apply on scripts which run in sequencing and continuous

while True:
    try:
        for symbol in symbol:
            script()

    except Exception as e:
        for symbol in symbol:
            script()
        continue

Solution

  • I guess you are trying to run a program even when there is an exception and break at some condition, you do not want to run the loop infinitely I suppose. you can do

    While true:
        try:
            for symbol in symbols:
                script(symbol) ' you should break however somewhere
        Exception as e:
            continue