Total noob here so be gentle. I\'ve looked everywhere and can\'t seem to find the answer to this. How do I condense the following?
if (expression)
{
re
Since expression is boolean:
return expression;
All you'd need in your case is:
return expression;
The reason why is that the expression itself evaluates to a boolean value of true
or false
, so it's redundant to have an if
block (or even a ?:
operator).
If expression
returns a boolean, you can just return the result of it.
Example
return (a > b)
return (expression) ? value1 : value2;
If value1
and value2
are actually true
and false
like in your example, you may as well just
return expression;