Questions about this topic? Sign up to ask in the talk tab.

Perl/Basics/Loops/While

From NetSec
Jump to: navigation, search
  • A while loop executes while a condition is true.
my $switch;
my $counter;
while (undef $switch) {
    print $counter;
    $counter++;
    $switch = 1 if ($counter > 100);
}
 The above code will execute until $switch is defined.

It is possible to create an infinite loop using while (1) { ... }.