last 退出当前循环

[oracle@PD sbin]$ cat t2.pl 
   for ($i=1;$i<=3;$i++){
      $j=0;
      print "$i is $i
";
      while (1==1){
      $j++;
      print "$j is $j
";
      if ("$j" == "5") { last;}
      };
     };
      
[oracle@PD sbin]$ perl t2.pl 
$i is 1
$j is 1
$j is 2
$j is 3
$j is 4
$j is 5
$i is 2
$j is 1
$j is 2
$j is 3
$j is 4
$j is 5
$i is 3
$j is 1
$j is 2
$j is 3
$j is 4
$j is 5

原文地址:https://www.cnblogs.com/hzcya1995/p/13349948.html