Http web server - Chapter 4 Control Structures: Part 1 151 During
Chapter 4 Control Structures: Part 1 151 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 finger of blame was pointed at the goto statement (used in several programming languages, including C and Basic), which allows the programmer to specify a transfer of control to one of a very wide range of possible destinations in a program. The notion of so-called structured programming became almost synonymous with goto elimination. Java does not have a gotostatement; however, gotois a reserved word and should not be used in a Java program. The research of Bohm and Jacopini1 had demonstrated that programs could be written without any gotostatements. The challenge of the era for programmers was to shift their styles to goto-less programming. It was not until the 1970s that programmers started taking structured programming seriously. The results have been impressive, as software development groups have reported reduced development times, more frequent on-time delivery of systems and more frequent within-budget completion of software projects. The key to these successes is that structured programs are clearer, easier to debug and modify and more likely to be bug free in the first place. Bohm and Jacopini s work 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 sequence structure is built into Java. Unless directed otherwise, the computer executes Java statements one after the other in the order in which they are written. The flowchart segment in Fig. 4.1 illustrates a typical sequence structure in which two calculations are performed in order. A flowchart is a graphical representation of an algorithm or a portion of an algorithm. Flowcharts are drawn using certain special-purpose symbols, such as rectangles, diamonds, ovals and small circles; these symbols are connected by arrows called flowlines, which indicate the order in which the actions of the algorithm execute. Like pseudocode, flowcharts are often useful for developing and representing algorithms, although pseudocode is strongly preferred by many programmers. Flowcharts show clearly how control structures operate; that is all we use them for in this text. The reader should carefully compare the pseudocode and flowchart representations of each control structure. add grade to total add 1 to counter total = total + grade; counter = counter + 1; Fig. 4.1Flowcharting Java s sequence structure. Fig. 1. Bohm, 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. 336 371. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01