2.10. The while Control StructureLike most algorithmic programming languages, Perl has a number of looping structures.[65] The while loop repeats a block of code as long as a condition is true:
$count = 0; while ($count < 10) { $count += 1; print "count is now $count\n"; # Gives values from 1 to 10 } As always in Perl, the truth value here works like the truth value in the if test. Also like the if control structure, the block curly braces are required. The conditional expression is evaluated before the first iteration, so the loop may be skipped completely, if the condition is initially false. Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|