chrismassey
Programmer
Hello,
I have a script which performs 3 tasks.
1) While the counter = less than 100, print the counter value then + 1
2) While the counter = more than 0, print the counter value then - 1
3) While the counter = more than 0, print the counter value then - 1, (skip the number 7)
The first 2 tasks work fine, but the last (3) isn't printing anything. The demo is available at
Thanks, Chris
I have a script which performs 3 tasks.
1) While the counter = less than 100, print the counter value then + 1
2) While the counter = more than 0, print the counter value then - 1
3) While the counter = more than 0, print the counter value then - 1, (skip the number 7)
The first 2 tasks work fine, but the last (3) isn't printing anything. The demo is available at
Code:
#! /usr/bin/perl
use strict;
use CGI ':standard';
## Declare variables
my ($counter);
print "Content-type: text/html\n\n";
## Loop 1
$counter == 0;
print "<p><font face=arial size=3>While the counter = less than 100, print the counter value then + 1</font><p>";
while ($counter < 100) {
print "<font face=arial size=3>$counter, </font>";
$counter = $counter + 1;
}
## Loop 2
$counter == 100;
print "<p><font face=arial size=3>While the counter = more than 0, print the counter value then - 1</font><p>";
while ($counter > 0) {
print "<font face=arial size=3>$counter, </font>";
$counter = $counter - 1;
}
## Loop 3
$counter == 100;
print "<p><font face=arial size=3>While the counter = more than 0, print the counter value then - 1, (skip the number 7)</font><p>";
while ($counter > 0) {
if ($counter == 7) {
print "<font face=arial size=3>Skip</font>";
}
else {
print "<font face=arial size=3>$counter, </font>";
}
$counter = $counter - 1;
}
## End
Thanks, Chris