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

Perl/Basics/Loops/While

From NetSec
Revision as of 03:58, 16 July 2012 by AlizaLorenzo (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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) { ... }.