Book
Collection
Click for Table of Contents
© 2025 by Rance D. Necaise
C Primer for Python Programmers
Copyright © 2025
Rance D. Necaise

1.4 Statement Categories

High-level programming languages not only provide the advantage of working with English-like phrases, but they also provide syntax for designing and creating well-structured programs. In fact, some languages require the programs to be designed in a structured fashion. There are four categories of structured statements found in most high-level languages: sequential, selection, repetition, and subprogram.

In the normal flow of execution, statements are executed in sequential fashion, one after the other. That is, an instruction is fetched from memory and executed, the next instruction that immediately follows the first is then fetched and executed, and so on. Think of sequential statements as if you were driving down a stretch of road with no side streets or driveways.

Sometimes, we may need to make decisions and execute one statement given a specific condition and skip it under other conditions. The selection statements (sometimes called branch or decision) change the normal sequential flow of execution to allow for different paths through the statements or to select specific statements to be executed. After the selected statement is executed, the flow of execution continues sequentially to the next statement. Extending our analogy of driving along a road, the selection statements would be similar to encountering a fork in the road in which you have to decide which direction to go and then continue down the road on the selected path.

The regular sequential flow of execution typically starts at the top and progresses downward, statement by statement. But what if we need to repeat one or more earlier statements? Consider the example of searching for a parking space along one-way streets near your ultimate destination. If it's busy, you may have to go around the block multiple times until you find an available space or you come to a roundabout and miss your turn so you have to go around again. The repetition statements (sometimes called a loop) changes the flow of execution to jump back to execute one or more earlier statements until some condition is met.

The final category of statements are called subprograms. A subprogram is like a small program that consists of a small number of statements for solving a simple problem. The subprograms are typically stored separately from the main program statements and must be called (or executed) explicitly when needed. When a subprogram is executed, the normal flow of execution stops and jumps to the first statement in the subprogram. The statements in the subprogram are then executed following the normal flow. Once the subprogram has completed its work, the flow of execution returns to the first statement following where it was called. Subprograms provide a means to subdivide a larger program into smaller parts that are then assembled to create the final program.