I would move the evaluation of the conditions into separate functions and then do:
for (int i = 0; i < imax; ++i) {
if (conditionA() && conditionB() && conditionC()) continue;
// do something
}
If conditionA
returns false
, conditionB
will never be called, and so on.
This will also make your function shorter and more concise, dividing responsibilities up among other functions.
If you have no good reason for doing an "early exit" like that, you can avoid using continue
altogether:
for (int i = 0; i < imax; ++i) {
if (!(conditionA() && conditionB() && conditionC())) {
// do something
}
}
Or use De Morgan's law to get !conditionA() || !conditionB() || !conditionC
- whichever you prefer.