Currently I have some code in the if (roobaf)
block which depends on foo
and bar
being false. I can check these conditions again within the block but it feels like unnecessary repetition of code.
if (foo) {
// some code
}
/*else*/ if (bar) { // bar is a condition which needs to be checked
// whether 'foo' is true or false
// more code
}
if (roobaf) {
if (!foo && !bar) {
// even more code
}
}
The problem is that if bar
is just an if
, then roobaf
will be reached even if foo is true.
If I change bar
to an else if
then if foo
is true then bar
will not be checked.
How do I make sure that foo
and bar
are always checked but that roobaf
will only be checked if both foo
and bar
are checked?
roobaf
is a condition which is not mutually exclusive with foo
and bar
so putting it first will not work.
you could do something like this:
if (foo || bar) {
if (foo) {
// do something
}
if (bar) {
// do something
}
}
else {
if (roobaf) {
// do something else
}
}
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