How do you handle huge if-conditions?

后端 未结 21 1724
一向
一向 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条回答
  •  清酒与你
    2021-01-31 17:40

    If I was doing it in Perl, This is how I might run the checks.

    {
      last unless $var1;
      last unless $var2;
      last unless $var3;
      last unless $var4;
      last unless $var5;
      last unless $var6;
    
      ... # Place Code Here
    }
    

    If you plan on using this over a subroutine replace every instance of last with return;

提交回复
热议问题