4.2 Flow of Execution

Logic Flow

Every algorithm has some type of logic flow. It is very easy to demonstrate logic flow using a flowchart. Let’s revisit the algorithm for driving from Chapter 1 but this time illustrate it using the flowchart in Figure 4-1.

Flowchart directions of
Figure 4-1. Flowchart directions of Figure 1-1

To properly move through the flowchart, start in the box that has the word Start in it, perform the step in that box, and then follow the arrow to the next box. Continue this process until there is nowhere else to go in the chart. If you walked through this flowchart, you would see that each step is performed once before moving on to the next step. This is known as one-directional flow. Algorithms with a one-directional logic flow do not really warrant a flowchart. However, not all algorithms are that simple, and not all flow is in one direction; that is, multiple possible execution flows exist. For example, Figure 4-2 shows a non-one-directional logical flow that models a choice between the two directions presented in Figures 1-1 and 1-2 found in Chapter 1.

Multiple-path logic flowchart
Figure 4-2. Multiple-path logic flowchart

To move through the flowchart in Figure 4-2, start in the uppermost box and follow the arrow to the next box. In this box, there is a condition and two arrows, but you pick one based on the outcome of the condition. After this, move on to the next box, and the rest of this diagram is one-directional. This type of flow, where a certain condition must be met to carry out the next step, is called conditional flow. We will talk about this in more detail later in the chapter. Also, later in the chapter, we refine the flowchart structure.

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

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