Emulate a do-while loop in Python?

后端 未结 16 1082
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 06:47

I need to emulate a do-while loop in a Python program. Unfortunately, the following straightforward code does not work:

list_of_ints = [ 1, 2, 3 ]
iterator =         


        
16条回答
  •  Happy的楠姐
    2020-11-22 07:30

    For me a typical while loop will be something like this:

    xBool = True
    # A counter to force a condition (eg. yCount = some integer value)
    
    while xBool:
        # set up the condition (eg. if yCount > 0):
            (Do something)
            yCount = yCount - 1
        else:
            # (condition is not met, set xBool False)
            xBool = False
    

    I could include a for..loop within the while loop as well, if situation so warrants, for looping through another set of condition.

提交回复
热议问题