4.2. Control Structures

Normally, statements in a program execute one after the other in the order in which they’re written. This is called sequential execution. Various C++ statements we’ll soon discuss enable you to specify that the next statement to execute may be other than the next one in sequence. This is called transfer of control.

During the 1960s, it became clear that the indiscriminate use of transfers of control was the root of much difficulty experienced by software development groups. Blame was pointed at the goto statement, which allows you to specify a transfer of control to one of a wide range of possible destinations in a program (creating what’s often called “spaghetti code”). The notion of so-called structured programming became almost synonymous with “goto elimination.”

Böhm and Jacopini’s1 research demonstrated that all programs could be written in terms of only three control structures, namely, the sequence structure, the selection structure and the repetition structure. The term “control structures” comes from the field of computer science. When we introduce C++’s implementations of control structures, we’ll refer to them in the terminology of the C++ standard document as “control statements.”

1. Böhm, C., and G. Jacopini, “Flow Diagrams, Turing Machines, and Languages with Only Two Formation Rules,” Communications of the ACM, Vol. 9, No. 5, May 1966, pp. 366–371.

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

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