uniblab icon

3 stupid and wrong ways of formatting conditionals (and One Right Way)

uniblab | PRO | 03/30/21 05:12:07 AM UTC | 0 ⭐ | 2337 👁️ | Never ⏰ | []
C# |

350 B

|

None

|

0 👍

/

0 👎

// WRONG!
if ( foo == bar || bar == baz || baz == quux ) {
    // code here
}
 
// WRONG!
if ( foo == bar 
    || bar == baz 
    || baz == quux ) {
    // code here
}
 
// WRONG!
if ( foo == bar 
    || bar == baz 
    || baz == quux )
{
    // code here
}
 
 
// CORRECT
if (
    ( foo == bar )
    || ( bar == baz )
    || ( baz == quux )
) {
    // code here
}

Comments