【问题标题】:While loop and For loop together [closed]While循环和For循环一起[关闭]
【发布时间】:2020-05-02 20:49:41
【问题描述】:

您好,我想运行 make for 循环以无限运行。

例如。

while True:

    try:
     script()

except Exception as e:
        script()
        continue

如下,因为在 For 循环中,我有列表,我想将这些列表应用于按顺序和连续运行的脚本

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

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

【问题讨论】:

    标签: python for-loop while-loop infinite-loop do-loops


    【解决方案1】:

    我猜你正在尝试运行一个程序,即使出现异常并在某些情况下中断,我想你也不想无限地运行循环。你可以做

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

    【讨论】:

    • 这个循环中没有任何东西会破坏while循环,它将永远运行
    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 2016-03-25
    • 2014-03-22
    • 1970-01-01
    • 2017-02-19
    • 2020-09-17
    • 1970-01-01
    • 2015-01-15
    相关资源
    最近更新 更多