Perl Breaking out of an If statement

后端 未结 7 843
深忆病人
深忆病人 2021-02-05 03:50

This one just came up: How do I break out of an if statement? I have a long if statement, but there is one situation where I can break out of it early on.

In

7条回答
  •  伪装坚强ぢ
    2021-02-05 04:20

    You can use basic block which is subject to last, next and redo, so there is possible break from it.

    if ($condition) {EXIT_IF:{
    
       last EXIT_IF; # break from code block
    
       print "never get's executed\n";
    }}
    

    EXIT_IF: {
      if ($condition) {
    
         last EXIT_IF; # break from code block
    
         print "never get's executed\n";
      }
    }
    

提交回复
热议问题