Emulate a do-while loop in Python?

后端 未结 16 905
伪装坚强ぢ
伪装坚强ぢ 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:20

    See if this helps :

    Set a flag inside the exception handler and check it before working on the s.

    flagBreak = false;
    while True :
    
        if flagBreak : break
    
        if s :
            print s
        try :
            s = i.next()
        except StopIteration :
            flagBreak = true
    
    print "done"
    

提交回复
热议问题