I've a conditional statement expensive_foo() which is false in 99.9% cases. And I have a conditional statement bar which is true in ~50% cases.
And I want some action be done if both statements are true. So I almost certainly know that expensive_foo() is false and I want to check it only if bar is true.
Will the code below check the expensive_foo() ONLY if bar is true? Or it will check expensive_foo() every time?
if ( bar && expensive_foo() ) { ... } Or I need to make a structure like this:
if ( bar ) { if ( expensive_foo() ) { ... } }
foowill only be checked ifbaris true. Though, I have to admit, I don't see the performance benefit from saving a single boolean comparision..bar && heavy_method_yielding_foo()orfoo = heavy_method(); if(bar && foo) ...?