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

Difference between revisions of "Perl/Basics/Loops/While"

From NetSec
Jump to: navigation, search
(Created page with "* A '''while loop''' executes '''while''' a condition is '''true'''. {{code|text=<source lang="perl">my $switch; my $counter; while (undef $switch) { print $counter; $cou...")
 
(No difference)

Latest revision as of 03:58, 16 July 2012

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