touque.ca > Education Commons > Java > Resources > Control

Loops

Two main types

  1. determinate: we know in advance how many times the loop body will execute
  2. indeterminate: we do not know in advance how many times the loop body will execute

Two main subtypes

  1. pre-test: test first, then execute loop body; minimum number of executions: 0
  2. post-test: loop first, then test; minimum number of executions: 1

Questions to aid in selection

  1. Do we know how many times the loop body should execute?
    • If yes, use a for loop
  2. What is the minimum number of executions of the loop body?
    • if 0, use a while loop
    • if 1, use a do … while loop

Arkin’s GNFRFCPWL

  1. write the boolean expression
  2. prime the boolean expression
  3. write the loop body
  4. refresh the boolean expression

touque.ca > Education Commons > Java > Resources > Control

[This page last updated 2020-12-23 at 12h13 Toronto local time.]