Section 4.9 Formulating Algorithms: Counter-Controlled Repetition

• Counter-controlled repetition (p. 115) uses a variable called a counter (or control variable) to control the number of times a set of statements execute.

• Counter-controlled repetition is often called definite repetition (p. 115), because the number of repetitions is known before the loop begins executing.

• A total (p. 115) is a variable used to accumulate the sum of several values. Variables used to store totals are normally initialized to zero before being used in a program.

• A local variable’s declaration must appear before the variable is used in that method. A local variable cannot be accessed outside the method in which it’s declared.

• Dividing two integers results ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.