C.4. Control Structures

Normally, statements in a program are executed one after the other in the order in which they’re written. This process is called sequential execution. Various Java statements, which we’ll soon discuss, enable you to specify that the next statement to execute is not necessarily 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. The blame was pointed at the goto statement (used in most programming languages of the time), which allows you to specify a transfer of control to one of a wide range of destinations in a program. The term structured programming became almost synonymous with “goto elimination.” [Note: Java does not have a goto statement; however, the word goto is reserved by Java and should not be used as an identifier in programs.]

Research had demonstrated that programs could be written without any goto statements. The challenge of the era for programmers was to shift their styles to “goto-less programming.” Not until the 1970s did most programmers start taking structured programming seriously. The results were impressive. The key to these successes was that structured programs were clearer, easier to debug and modify, and more likely to be bug free in the first place.

Researchers demonstrated that all programs could be written in terms of only three control structures—the sequence structure, the selection structure and the repetition structure. When we introduce Java’s control structure implementations, we’ll refer to them in the terminology of the Java Language Specification as “control statements.”

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

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