1 Pluspunkt 0 Minuspunkte

Wie kann ich eine Schleife in Perl abbrechen wie mit break?

my $count = 0;
while ($count < 5) {
    print "$count\n";
    $count++;
}
von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

Dazu gibt es das Keyword last.

my $count = 0;
while ($count < 5) {
    print "$count\n";
    $count++;

    last if $count == 3;

}

von (532 Punkte)