Chapter 3

Control

The purpose of this chapter is to explain the flow of control that the C programming language supports. Statements in a sequential program are normally executed one after the other [Refer to Sequence Construct, Fig. 1.3 (a)]. This is also called sequential flow of control. However, it might be often desirable to alter this sequential flow to provide for a choice of action or a repetition of action [Refer to Selection Constructs, Fig. 1.3 (b), and Repetition Constructs, Fig. 1.3 (c)]. We can make a selection among alternative actions using the if, the if-else, and the switch statements. The while, for, and do-while statements help us to perform iterative actions. In addition, break and continue can be used in conjunction with ...

Get C Programming Essentials 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.