CHAPTER 44 — The do Statement

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.

created: 12/12/99; revised: 01/22/00, 07/20/02, 05/27/03, 01/29/06

CHAPTER 44 — The do Statement

Loops are so important, and are so common in programs, that there are several Java language features for implementing them. You have already seen while loops and for loops. This chapter looks at do loops.

A programming language needs to have only one general looping method. In Java, the while statement can be used to implement any loop. However, as we have seen, the for statement is very convenient. The do loop is occasionally convenient. Of the three looping statements, it is used the least. Some programmers prefer not to use it at all.

Chapter Topics:

  • The do statement
  • Bottom-driven loops
  • Dangers of bottom-driven loops

The do statement is not part of the AP (Advanced Placement) computer science test given to high school students in the US. It is not used in the chapters that follow this one.

QUESTION 1:

There are several looping statements in Java, although only one (any one of them) is logically necessary.

Are there also several branching statements in Java?