|
|
The 'while' loop in Perl is a very useful construct that is similar to its counterparts in C and many other programming languages. A 'while' loop exits when a specified condition is no longer true, and the location of this condition can either be in the 'while' statement itself or, by means of 'if/then' logic, inside the loop. Listing C.2 contains an example of a 'while' loop for printing the integers from 0 to 9 inclusive.
Listing C.2 whileLoop1.pl
my($count) = 0; while($count++ < 10 ) { print "count -> $count\n"; }
You can launch the Perl script in whileLoop1.pl in Listing C.2 from the command line as follows,
perl -w whileLoop1.pl
and the output is as follows
count -> 0 count -> 1 count -> 2 count -> 3 count -> 4 count -> 5 count -> 6 count -> 7 count -> 8 count -> 9
|
|