Perl - Part 12
[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]
Repetition without calculation
The last programs made use of while statements to carry out actions repeatedly. In all of the examples, some calculations were involved. These calculations may even have been the purpose of the loop. Certainly, the statements were controlled by numbers at the very least.
This is not always the case. Some while statements have very little to do with numbers, except incidentally, and may have control over iteration (or not) determined by text input, such as 'y' for Yes and 'n' for No. This will be the case in this next task.
Task 016
Copy the responder.pl into the file responder-xx.pl; then modify the file to give output similar to that below:

In summary, this is the last created of the responder programs with a while loop around it. Rather like this:
#!/usr/bin/perl
#
#--------------------------------------------------------------------------
# Author: Date:
# Title: responder-xx.pl Purpose:
#--------------------------------------------------------------------------
#
while_variable_initialisation_bit
while (condition)
{
the former responder program
copied into the while loop,
indented, re-used.
ask to run again (as you've asked for input before)
the input given controls the while (condition) above
}
Essentially the program re-uses existing code - perfectly allowable, recommended even, in programming - surrounds that code with a controlling loop that keeps the code looping until a small 'n' is entered. When this is entered the loop, and the program, stops.
Click on, Brave Soul...
[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]
Last updated: 20120108-16:13