Relationship Between Data Types and Control Structures

Data types and control structures relate to each other in well-defined ways that were originally described by the British computer scientist Michael Jackson (Jackson 1975). This section sketches the regular relationship between data and control flow.

Jackson draws connections between three types of data and corresponding control structures:

Sequential data translates to sequential statements in a program. Sequences consist of clusters of data used together in a certain order, as suggested by Figure 10-2. If you have five statements in a row that handle five different values, they are sequential statements. If you read an employee's name, Social Security Number, address, phone number, and age from a file, you'd have sequential statements in your program to read sequential data from the file.

Sequential data is data that's handled in a defined order

Figure 10-2. Sequential data is data that's handled in a defined order

Cross-Reference

For details on conditionals, see Chapter 15.

Selective data translates to if and case statements in a program. In general, selective data is a collection in which one of several pieces of data is used at any particular time, but only one, as shown in Figure 10-3. The corresponding program statements must do the actual selection, and they consist of if-then-else or case statements. If you had an employee payroll program, you might process employees differently depending on whether they were paid hourly or salaried. Again, patterns in the code match patterns in the data.

Selective data allows you to use one piece or the other, but not both

Figure 10-3. Selective data allows you to use one piece or the other, but not both

Cross-Reference

For details on sequences, see Chapter 14.

Iterative data translates to for, repeat, and while looping structures in a program. Iterative data is the same type of data repeated several times, as suggested by Figure 10-4. Typically, iterative data is stored as elements in a container, records in a file, or elements in an array. You might have a list of Social Security Numbers that you read from a file. The iterative data would match the iterative code loop used to read the data.

Iterative data is repeated

Figure 10-4. Iterative data is repeated

Cross-Reference

For details on loops, see Chapter 16.

Your real data can be combinations of the sequential, selective, and iterative types of data. You can combine the simple building blocks to describe more complicated data types.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.152.139