I've got this code. true_var and other_true_var are boolean values. The four conditional branches are distinct.
if true_var && other_true_var:
# do something 0
else if true_var && not other_true_var:
# do something 1
else if not true_var && other_true_var:
# do something else
else:
# both are false, do a crazy thing
Is there an "accepted" way to write this? I could pull all the conditionals into methods which return a boolean, but that seems over the top.
I would do it as follows for minimum number of tests:
if (A)
{
if (B) { // case 0 }
else { // case 1 }
}
else
{
if (B) { // something else }
else { / crazy }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With