How do you handle huge if-conditions?

后端 未结 21 1736
一向
一向 2021-01-31 17:14

It\'s something that\'s bugged me in every language I\'ve used, I have an if statement but the conditional part has so many checks that I have to split it over multiple lines, u

21条回答
  •  -上瘾入骨i
    2021-01-31 17:50

    I've seen a lot of people and editors either indenting each condition in your if statement with one tab, or matching it up with the open paren:

    if (var1 == true
        && var2 == true
        && var3 == true
       ) {
        /* do something.. */
    }
    

    I usually put the close paren on the same line as the last condition:

    if (var1 == true
        && var2 == true
        && var3 == true) {
        /* do something.. */
    }
    

    But I don't think this is quite as clean.

提交回复
热议问题