Section 6.13 Chapter Summary
Subsection 6.13.1 Technical Term
conditional loop | loop bound | sentinel bound |
counting loop | loop entry condition | unit indexing |
do-while statement | nested loop | updater |
infinite loop | postcondition | while statement |
initializer | precondition | zero indexing |
limit bound | priming read | |
loop body | repetition structure |
Subsection 6.13.2 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 elements—an initializer, a loop entry condition or a loop boundary 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:A summary of various loop bounds:for ( initializer ; loop entry condition ; updater ) { for loop body }
Bound Example Counting k \(\lt\) \(100\) Sentinel input != 9999 Flag done != true Limit amount \(\lt\) \(0.5\) - 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 condition );
- When designing a loop, it is important to analyze the loop structure to make sure that the loop bound will eventually be satisified. The table below summarizes the types of loop bounds that we have identified.
- Structured programming is the practice of writing programs that are built up from a small set of predefined control structures—the sequence, selection, repetition, and method-call structures. An important feature of these structures is that each has a single entry and exit.
- A precondition 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. Preconditions and postconditions should be used in the design, coding, documentation, and debugging of algorithms and methods.
Solutions 6.13.3 Solutions to Self-Study Exercises
6.3 Counting Loops
6.3.7 Self-Study Exercises
6.3.7.2. For Loop Bugs 2.
6.3.7.3. Infinite Loops.
6.3.7.4. Variable j in Loop.
6.3.7.5. Count by 4’s.
6.3.8 Nested Loops
Self-Study Exercise
6.3.8.1. Nested Loop Pattern.
6.6 Conditional Loops
6.6.1 The While Structure, Revisited
Self-Study Exercises
6.6.1.1. While Loop Bugs 1.
6.6.1.2. While Loop Bugs 2.
6.6.1.3. While Loop Bugs 3.
6.6.1.4. While Loop Bugs 4.
6.6.1.5. Count by 6’s.
6.6.1.6. While Sequence.
6.6.2 The Do-While Structure
Self-Study Exercises
6.6.2.1. Do While Loop Bugs 1.
6.6.2.2. Do While Loop Bugs 2.
6.6.2.3. Count by 7’s.
6.6.2.4. Pizza Costs.
6.6.2.5. Pizza Codes.
6.9 Principles of Loop Design
6.9.1 Loop Summary
Self-Study Exercise
6.9.1.1. Loop Choices.
6.10 The switch
Multiway Selection Structure
6.10.1 Switch
Self-Study Exercises
6.10.1.1. Switch Bug 1.
6.10.1.2. Switch Bug 2.
6.10.1.3. Switch Bug 3.
6.10.1.4. Ice Cream Flavors.
6.11 OBJECT-ORIENTED DESIGN: Structured Programming
6.11.4 Effective Program Design
Self-Study Exercises
6.11.4.1. Pre/Post Conditions 1.
6.11.4.2. Pre/Post Conditions 2.
You have attempted of activities on this page.