Perl Breaking out of an If statement

后端 未结 7 861
深忆病人
深忆病人 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

    Keep your while loop so you can use last but also make sure that the loop is executed at most once

    my $loop_once = 1;
    while ( $loop_once-- and some_condition ) {
        blah, blah, blah
        last if $some_other_condition; # No need to continue...
        blah, blah, blah
        ...
    }
    

提交回复
热议问题