Chapter 24 Introduction to Loop Control Structures

24.1 What is a Loop Control Structure?

A loop control structure is a control structure that allows the execution of a statement or block of statements multiple times until a specified condition is met.

24.2 From Sequence Control to Loop Control Structures

The next example lets the user enter four numbers and it then calculates and displays their sum. As you can see, there is no loop control structure employed yet, only the familiar sequence control structure.

double x, y, z, w, total;
 
x = Double.parseDouble(cin.nextLine());
y = Double.parseDouble(cin.nextLine());
z = Double.parseDouble(cin.nextLine());
w = Double.parseDouble(cin.nextLine());
 
total = x + y + z + w;
 
System.out.println(total); ...

Get Java and Algorithmic Thinking for the Complete Beginner 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.