CHAPTER 4
LOOPS
CHAPTER GOALS
To implement while, for, and do loops
To hand-trace the execution of a program
To become familiar with common loop algorithms
To understand nested loops
To implement programs that read and process data sets
To use a computer for simulations
CHAPTER CONTENTS
Common Error 4.1: Don't Think "Are We There Yet?"
Common Error 4.2: Infinite Loops
Common Error 4.3: Off-by-One Errors
Random Fact 4.1: The First Bug
4.2 PROBLEM SOLVING: HAND-TRACING
Programming Tip 4.1: Use for Loops for Their Intended Purpose Only
Programming Tip 4.2: Choose Loop Bounds That Match Your Task
Programming Tip 4.3: Count Iterations
Programming Tip 4.4: Flowcharts for Loops
4.5 APPLICATION: PROCESSING SENTINEL VALUES
Special Topic 4.1: The Loop-and-a-Half Problem and the break Statement
Special Topic 4.2: Redirection of Input and Output
Video Example 4.1: Evaluating a Cell Phone Plan
4.6 PROBLEM SOLVING: STORYBOARDS
Worked Example 4.1: Credit Card Processing
Worked Example 4.2: Manipulating the Pixels in an Image
4.9 APPLICATION: RANDOM NUMBERS AND SIMULATIONS
Get Java For Everyone: Compatible with Java 5, 6, and 7, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.