Redo for loop iteration in Python

前端 未结 6 1416
灰色年华
灰色年华 2020-12-10 04:07

Does Python have anything in the fashion of a \"redo\" statement that exists in some languages?

(The \"redo\" statement is a statement that (just like \"break\" or \

6条回答
  •  一向
    一向 (楼主)
    2020-12-10 04:15

    There is no redo in python. A very understandable solution is as follow:

    for x in mylist:
        redo = True
        while redo:
            redo = False
    
            If should_redo:
                redo = True
    

    It's clear enough to do not add comments

    Continue will work as if it was in the for loop

    But break is not useable, this solution make break useable but the code is less clear.

提交回复
热议问题