Example five a - loop structures


#Example five a - example of loop structures.
# adapted by Al Bento
# Source: Kernighan and Ritchie,
# The C Programming Language, Prentice-Hall, 1978.
# Print Farenheit-Celsius Table

#variables used in the example

$lower = 0;     # lowest temperature
$upper = 300;   # highest temperature
$step = 20;      # increment step

# a simple while structure

$fahr = $lower;
while ($fahr <= $upper) {
     $celsius = 5/9 * ($fahr-32);
     print "$fahr $celsius\n";
     $fahr = $fahr + $step;
}

# a simple until structure

$fahr = $lower;
until ($fahr > $upper) {
     $celsius = 5/9 * ($fahr-32);
     print "$fahr $celsius\n";
     $fahr = $fahr + $step;
}

download the script


This page is maintained by Al Bento who can be reached at abento@ubmail.ubalt.edu. This page was last updated on February 15, 2001. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.