7.2 Algorithms with Simple Variables

Simple (atomic) variables are those that cannot be divided. They are a value stored in a place. We used simple variables in the algorithms in Chapter 6.

An Algorithm with Selection

Suppose you want to write an algorithm to express what dress is appropriate for a given outside temperature. You would like to wear shorts if it is hot, short sleeves if it is nice but not too hot, a light jacket if the temperature is chilly, and a heavy coat if it is cold. If the temperature is below freezing, you stay inside.

The top-level (main) module just expresses the tasks.

The first two statements do not need further decomposing. However, Determine ...

Get Computer Science Illuminated, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.