Knowing when a new control structure is needed
If you google the definition of a control structure, it will say something like “control structures determine the order in which one or more chunks of code execute.” This definition is fine for traditional mainstream languages. It focuses on control flow, and it addresses two kinds of control structures: choosing which (or whether) to execute and code (loops) that can repeat under some conditions. The if
statements and while
loops that we implemented for Jzero earlier in this book are good examples.
Higher-level languages tend to have a more nuanced view of control structures. For example, in a language with built-in backtracking, the order in which chunks of code may execute becomes more complicated. This book will paraphrase Ralph Griswold’s definition of a control structure in the Icon programming language: a control structure is an expression containing two or more subexpressions in which one subexpression...