Created
April 23, 2012 17:44
-
-
Save rizkyabdilah/2472636 to your computer and use it in GitHub Desktop.
Using while-break to prevent 'ugly' nested if
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example nested if, in real life it will be uglier | |
if a: | |
# do some code with a | |
if b: | |
# do some code with a and b | |
if c: | |
# do some code with a, b and c | |
else: | |
print "you must set b" | |
else: | |
print "a is not set, so b no check" | |
# its better | |
while True: | |
if not a: | |
print "a is not set, so b no check" | |
break | |
# do some code with a | |
if not b: | |
print "you must set b" | |
break | |
# do some code with a and b | |
if c: | |
# do some code with a, b and c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment