Python lacks a do-while loop. So here is how I like to emulate one:
def do_while():
result = do_something()
if result:
return True
else:
return do_while()
And I figured that Python is tail-recursive and this would not blow the stack. Am I right?
Common Python implementations do not support the tail call elimination optimisation, so this will blow the stack. This is trivially demonstrated by using it to write an infinite loop:
Also, do-while loops continue iterating whilst the predicate is true, but your version continues while it its false. A version which corrects these flaws might look something like: