CHAPTER 15 — 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   hear noise   go to next page

Revised: 10/01/98, 08/04/99, 01/20/00, 03/30/00, 07/12/02, 03/05/06

CHAPTER 15 — Loops

Most modern machines work by endlessly repeating the same motions. The engine in your car cycles through the same motions over and over as it burns gasoline to provide power. Electric motors are similar. They convert electric power into circular motion. Because of their circular motions, these machines keep going as long as you want.

Computer programs use cycles, also. In programming, a cycle is called a loop. When a program has a loop in it, some statements are done over and over as long as is needed to get the work done. Most computer programs execute many millions of program statements each time they are used. Usually the same statements are executed many times. This chapter discusses several kinds of programming loops.

Chapter Topics:

  • The while statement
  • Syntax and semantics of the while statement
  • The loop body
  • Three parts of a loop that must be coordinated
  • Counting loops and the loop control variable

QUESTION 1:

Think of some machines (mechanical or other) that use cycles.