How to emulate a do-while loop?

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 = 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: … Read more

What condition does while(true) test? When is it true and false?

When is while(true) true, and when is it false? It’s always true, it’s never false. Some people use while(true) loops and then use break to exit them when a certain condition is true, but it’s generally quite sloppy practice and not recommended. Without the use of break, return, System.exit(), or some other such mechanism, it will keep looping forever.