How to layer if statements when order of logic is irrelevant?
Posted
by
jimmyjimmy
on Programmers
See other posts from Programmers
or by jimmyjimmy
Published on 2014-08-15T16:11:08Z
Indexed on
2014/08/20
16:34 UTC
Read the original article
Hit count: 213
Basically I have a series of logic in my website that can lead to 5 total outcomes. Basically two different if tests and then a catch all else statement.
For example:
if cond1:
if mod1:
#do things
elif mod2:
#do things
elif cond2:
if mod1:
#do things
elif mod2
#do things
else:
#do things
I was thinking about rewriting it like this:
if cond1 and mod1:
#do things
elif cond1 and mod2:
#do things
elif cond2 and mod1:
#do things
elif cond2 and mod2:
#do things
else:
#do things
Is there any real difference in these two coding options/a better choice for this kind of logic testing?
© Programmers or respective owner