Java Reference
In-Depth Information
4.3 Pseudocode
Pseudocode is an informal language that helps you develop algorithms without having to
worry about the strict details of Java language syntax. The pseudocode we present is par-
ticularly useful for developing algorithms that will be converted to structured portions of
Java programs. The pseudocode we use in this topic is similar to everyday English—it's
convenient and user friendly, but it's not an actual computer programming language.
You'll see an algorithm written in pseudocode in Fig. 4.7. You may, of course, use your
own native language(s) to develop your own pseudocode.
Pseudocode does not execute on computers. Rather, it helps you “think out” a pro-
gram before attempting to write it in a programming language, such as Java. This chapter
provides several examples of using pseudocode to develop Java programs.
The style of pseudocode we present consists purely of characters, so you can type
pseudocode conveniently, using any text-editor program. A carefully prepared pseudocode
program can easily be converted to a corresponding Java program.
Pseudocode normally describes only statements representing the actions that occur
after you convert a program from pseudocode to Java and the program is run on a com-
puter. Such actions might include input , output or calculations . In our pseudocode, we typ-
ically do not include variable declarations, but some programmers choose to list variables
and mention their purposes.
4.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. [ 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.]
The research of Bohm and Jacopini 1 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.” The term structured programming became
almost synonymous with “ goto elimination.” Not until the 1970s did most programmers
start taking structured programming seriously. The results were impressive. Software
development groups reported shorter development times, more frequent on-time delivery
of systems and more frequent within-budget completion of software projects. 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.
Bohm and Jacopini's work demonstrated that all programs could be written in terms
of only three control structures—the sequence structure , the selection structure and the
1.
C. Bohm, and G. Jacopini, “Flow Diagrams, Turing Machines, and Languages with Only Two For-
mation Rules,” Communications of the ACM , Vol. 9, No. 5, May 1966, pp. 336-371.
 
 
 
Search WWH ::




Custom Search