If the nested if-statement doesn’t fulfill a condition, how do I continue on to the outer if? Eg. I have this (very impractical) example:
a = 2
if( a > 1 ):
if( a == 3 ):
print "yes"
elif( a == 2 ):
print "yes"
I want a == 2 to be checked next. How would I do this?
(I have multiple conditions in that nested if that I need to check so I’d rather not have a huge string of and/or statements in that one outer-if. I also have more than one elif statement so I don’t want to mash all the elifs together under that nested one.)
A deeper example:
b = 8
if( a > 1 ):
if( b == 3 ):
doSomething()
elif( b == 4 ):
doSomethingElse()
elif( b == 5 ):
more()
elif( -1 <= a <= 1 ):
asd()
elif( a < -1 ):
if( b == 7 ):
asdfasdf()
elif( b == 8 ):
asasdf()
How do you expect this to be clear to a computer?
by definition will never execute anything in the second block.
I believe your intend might be more along this lines:
There are multiple ways to achieve this behaviour. I like the
function+returnpattern, because it structures code nicely. Another way is to use ahandledflag:(You can obviously put in a number of shortcuts here by using elif. But using explicit “if unhandled” makes the code more verbose about the logic and easier to add new options.)