Emulate a do-while loop in Python?

后端 未结 16 1047
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  遥遥无期
    2020-11-22 07:27

    The way I've done this is as follows...

    condition = True
    while condition:
         do_stuff()
         condition = ()
    

    This seems to me to be the simplistic solution, I'm surprised I haven't seen it here already. This can obviously also be inverted to

    while not condition:
    

    etc.

提交回复
热议问题