Perl-last

提供:Dev Guides
移動先:案内検索

Perlの最後の関数

説明

これは機能ではありません。 最後のキーワードは、ループの現在の反復をすぐに最後にするループ制御ステートメントです。 これ以上ステートメントは実行されず、ループは終了します。 LABELが指定されている場合、現在囲んでいるループではなく、LABELで識別されるループから脱落します。

構文

以下は、この関数の簡単な構文です-

last LABEL

last

戻り値

これは値を返しません。

以下は、その基本的な使用法を示すコード例です-

#!/usr/bin/perl

$count = 0;

while( 1 ) {
   $count = $count + 1;
   if( $count > 4 ) {
      print "Going to exist out of the loop\n";
      last;
   } else {
      print "Count is $count\n";
   }
}
print "Out of the loop\n";

上記のコードが実行されると、次の結果が生成されます-

Count is 1
Count is 2
Count is 3
Count is 4
Going to exist out of the loop
Out of the loop