- If you want to repeat a calculation for as long as a Boolean
expression's value is
true
, then use a while
loop:
while (Boolean expression)
embedded statement or block
- If you want to repeat a calculation involving entry, Boolean, and
continuation expressions, then use a
for
loop:
for (entry expression;
Boolean expression;
continuation expression)
embedded statement or block
- If you want to repeat a calculation until a variable is counted down to
0
, then use a counting loop:
for (counter-declaration-and-initialization expression;
counter-testing expression;
counter-reassignment expression)
embedded statement or block
- If you want to increment or decrement the value of a variable by 1,
then instantiate one of the following patterns:
++variable name
--variable name
- If you want to change a variable's value by combining it with the value
of an expression via addition, subtraction, multiplication, or division,
then consider instantiating the following pattern:
variable name operator= expression