- 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) { ... }.