Skip to main content

Section 3.2 WriteLoops-Exercise

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 the loop body
    1. Update Loop Control Variable to reach termination

Exercises Exercises

1.

Put the following code blocks in the correct order to create a program that will print the prime numbers between 1 and 100 (inclusive).
You have attempted 1 of 2 activities on this page.