# Subgoals

## Section8.3WriteLoops-WE1-P1

### Subgoals for Writing a Loop.

1. Determine purpose of loop
1. Pick a loop structure (while, for, do_while)
2. Define and initialize variables
3. Determine termination condition
1. Invert termination condition to continuation condition
4. Write loop body
1. Update loop control variable to reach termination

### Subsection8.3.1

#### ExercisesExercises

##### 1.
Q1: Put the code in the right order to create a program that will calculate and print the sum of 10 natural numbers.
##### 2.
Q2: Fill in the blanks in the following code to create a program that will print the even numbers between 1 and 20.
public class main{
public static void main(String[] args){
for (int i = ___A___; i <= ___B___; i++)
if (___C___ % ___D___ == ___E___)
System.out.println(i);
}
}

Blank A:
Blank B:
Blank C:
Blank D:
Blank E:
##### 3.
Q3: Put the code in the right order to create a program that will generate an integer between 0 and 10,000 (inclusive), print the number, calculate and print the number of digits in the number.
##### 4.
Q4: Put the code in the right order to create a program that will print out all Armstrong numbers between 1 and 500. If the sum of the cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = (1*1*1) + (5*5*5) + (3*3*3)