If have if block like that
if(foo() || foo2() || foo3())
{
//do some things
}
I need only one foo function to return true to execute that code.
But I have to call all of them.
Problem starts when first foo returns true. This way rest of foos (foo2 and foo3) are not being called.
I know that I can do it like that:
bool foo1 = foo1();
bool foo2 = foo2();
bool foo3 = foo3();
if(foo1 || foo2 || foo3) {}
But I have 18 foo functions and this is in few parts of my code.
Is there any trick to do it short and easy?
The
||operator is short circuiting. You could use|instead:But you should also consider making an array of function pointers and calling them in a loop.
You should refactor your code so that you can reuse it, rather than copying and pasting the same code in many places.