Chapter Summary


[Page 290]

Technical Terms

conditional loop

counting loop

do-while statement

for ststement

infinite loop

initializer

limit bound

loop body

loop bound

loop-entry condition

nested loop

postcondition

pre-condition

priming read

repetition structure

sentinel bound

switch/break structure

unit indexing

updater

while statement

zero indexing

Summary of Important Points
  • A repetition structure is a control structure that allows a statement or sequence of statements to be repeated.

  • All loop structures involve three elementsan initializer, a loop-entry condition or a loopboundary condition, and an updater.

  • When designing a loop, it is important to analyze the loop structure to make sure that the loop bound will eventually be satisfied.

  • The for statement has the following syntax:


    for ( initializerloop-entry conditionupdater )
                              loop body

  • The while statement takes the following form:


    while ( loop-entry condition )
                    loop body

  • The do-while statement has the following general form:


                do loop body
    while ( loop-entry condition );

  • When designing a loop, it is important to analyze the loop structure to make sure that the loop bound will eventually be satisfied. Table 6.2 summarizes the types of loop bounds that we have identified.

    Table 6.2. Summary of loop bounds
    (This item is displayed on page 291 in the print version)

    Bound

    Example

    Counting

    k < 100

    Sentinel

    input != 9999

    Flag

    done != true

    Limit

    amount < 0.5


  • Structured programming is the practice of writing programs that are built up from a small set of predefined control structuresthe sequence, selection, repetition, and method-call structures. An important feature of these structures is that each has a single entry and exit.


  • [Page 291]
  • A pre-condition is a condition that must be true before a certain code segment executes. A postcondition is a condition that must be true when a certain code segment is finished. Pre-conditions and postconditions should be used in the design, coding, documentation, and debugging of algorithms and methods.




Java, Java, Java(c) Object-Orienting Problem Solving
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition)
ISBN: 0131474340
EAN: 2147483647
Year: 2005
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net