在Python中模拟do-while循环?
问题: I need to emulate a do-while loop in a Python program. 我需要在Python程序中模拟do-while循环。 Unfortunately, the following straightforward code does not work: 不幸的是,以下简单的代码不起作用: list_of_ints = [ 1, 2, 3 ] iterator = list_of_ints.__iter__() element = None while True: if element: print element try: element = iterator.next() except StopIteration: break print "done" Instead of "1,2,3,done", it prints the following output: 而不是“1,2,3,完成”,它打印以下输出: [stdout:]1 [stdout:]2 [stdout:]3 None['Traceback (most recent call last): ', ' File "test_python.py", line 8, in <module> s = i.next() ', 'StopIteration '] What can