[Image of Linux]
Linux's Witness Ministry
The Personal Web Pages of Chris X. Edwards

ex-for.pl

--------------------------
#!/usr/bin/perl
#ex-for.pl
#for statement used for generating fixed loops

#1st arguement sets initial condition, 2nd sets test, 3rd sets increment
#can use commas within each arguement to set more than one variable
#eg. for ($x=0, $y=0; $x<=5, $y<+10; $x++, $y+=2)

print "normal for loop:\n";
for ($x=0; $x<5; $x++){ 
print $x, "\n";
}

print "\nnested for loops:\n";
for ($x=1; $x<=10; $x++){
  for ($y=1; $y<=12; $y++){
    print $x*$y, " ";
   } # end of y loop
  print "\n";
} #end of x loop


--------------------------
Return to Program Examples
This page was created with only free, open-source, publicly licensed software.
This page was designed to be viewed with any browser on any system.
Chris X. Edwards ~ January 2003