Write a WHILE LOOP in Perl, Carefully
CAUTION: Be careful with WHILE because it is quite easy to cause an endless loop (which is bad). If you don't have access to killing the script, you can crash your browser and the server machine.
Having said that, you create and name a variable $hu
$hu=0;
while ($hu < 10) {
print "$hu, ";
$hu++;
}
Which prints:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
In plain English:
The first time through the WHILE LOOP, $hu equals 0.
$hu is incremented by one each time with $hu++ which means $hu plus one.
When $hu reaches 10, the loop is exited because $hu is no longer less than 10.
If you forgot the $hu++, this script would endlessly loop, because $hu would always be zero. This would be bad and would crash your browser and probably the server. SO BE CAREFUL WITH THE "WHILE LOOP"!
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$hu=0;
while ($hu < 10) {
print "$hu, ";
$hu++;
}
exit;
While Loop Perl CGI - See in Action (new window)
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group