In C there's a clever trick that lets you avoid pyramid-style code by turning:
if (check1())
if (check2())
if (check3())
do_something();
into:
do {
if (!check1())
break;
if (!check2())
break;
if (!check3())
break;
do_something();
} while (0);
What's the cleanest way for me to do this in Python, which doesn't have a do-while construct?
Note: I'm not necessarily asking for a way to implement a do-while loop in Python, but a technique to avoid the aforementioned pyramid-style code.
Update: It seems there's some confusion. The only reason I'm using a loop is to be able to break out at any point in the body, which is only supposed to be executed once.
Essentially what I'm doing in Python is this:
while True:
if not check1():
break
if not check2():
break
if not check3():
break
do_domething()
break
I'm just wondering if there's a cleaner way.