Skip to content
Prev 175977 / 398503 Next

new line between '}' and 'else' in function body

you can always wrap the whole if/else statement into innocent braces or
parentheses, as in

    y = {
       if (x) 1
       else 2 }

    y = (
       if (x) 1
       else 2 )

it doesn't have to be a function, and there is no need for the
assignment either -- you just need to tell the parser that the input
hasn't ended.  that's a matter of taste, but i find

    { if (x) 1
       else 2 }

more readable than something like

    if (x) { 1
    } else 2

vQ
Yihui Xie wrote: