Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Trailer loops with data sets


1. Trailer loops with data sets
The trailer loop expects a value at the end of the input that is not part of the input.

How is a trailer loop best done when each line of data has more than one number? Let us look at some examples with more than one data number per line.

2. More information
See the following for more information. Here is the C code.


3. Examples of input and output
Here are some examples of input and output for the above program code.

Here is an example input.

For the above example input, here is the expected output. Here is an example input.

For the above example input, here is the expected output. Here is an example input.

For the above example input, here is the expected output.


4. Alternative method
When there is no data to be read, the programming language C will just read empty values, zeros for numbers, without an error.

Some programming languages will raise an error if an attempt is made to read beyond the end of the data.

Here is a way to handle this. Note only one value is input before determining whether the trailer value has been read. Here is the C code.


5. Examples of input and output
Here are some examples of input and output for the above program code.

Here is an example input.

For the above example input, here is the expected output. Here is an example input.

For the above example input, here is the expected output. Here is an example input.

For the above example input, here is the expected output.


6. Exercises
As an exercise, try changing the above examples to use parallel arrays of element variables and then an array of records with named field variables.

7. End of page