Good python equivalent to C goto
Christian Heimes
lists at cheimes.de
Sat Aug 16 17:42:19 EDT 2008
Kurien Mathew wrote:
> Hello,
>
> Any suggestions on a good python equivalent for the following C code:
>
There are various ways to write your example in Python. For example
while loopCondition:
condition = 1
while condition:
if condition1:
break
if condition2:
break
if condition3:
break
stmt1
stmt2
condition = 0
else:
stmt3
stmt4
The else block of while isn't execute if you break out of while.
You can emulate multiple gotos with exceptions. In general you shouldn't
try to mimic C in Python code. C like Python code is often hard to read
and slower than well designed Python code.
More information about the Python-list
mailing list