CHAPTER 19 — Result-controlled Loops

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to home page   go to next page

revised: 10/09/98, 08/09/99, 04/18/00, 07/13/02, 05/21/03, 01/15/06

CHAPTER 19 — Result-controlled Loops

A third kind of loop can be built from the fundamental control statements in Java. This is the result-controlled loop. (Other names for it are free loop and general loop). A result-controlled loop keeps looping until the computation has reached a particular goal. It is like the instruction in a cookie recipe that says "keep stirring until the ingredients are thoroughly blended." You know when to quit only when the desired result has been achieved.

Chapter Topics:

  • Result controlled loops
  • Example programs:
    • Savings account interest
    • Newton's method
  • Nested Loops
  • Improving an estimate by iteration
  • Precision of double precision variables

QUESTION 1:

You put $1000 in the bank at 5% annual interest. How much will you have at the end of one year?