CHAPTER 18 — Sentinel 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/04/98, 08/08/99, 01/20/00, 07/13/02, 05/21/03, 03/08/06

CHAPTER 18 — Sentinel Controlled Loops

The previous chapters have discussed loops in general, and counting loops in particular. The same statements that are used to build counting loops are used to build other kinds of loops. This chapter looks at a kind of loop called a sentinel controlled loop.

Chapter Topics:

  • Sentinel-controlled loops
  • Example programs:
    • Adding up a list of integers
    • evaluating polynomials
  • Using an if-else statement inside the loop body
  • Matching up if's with else's
  • Using a String value as a sentinel

QUESTION 1:

Say that a program is to add up a list of numbers entered from the keyboard. Will a loop be used in this program?