Loops


  • Is the loop entered from the top?
  • Is initialization code directly before the loop?
  • If the loop is an event loop, is it constructed cleanly rather than using a kludge such as for i:= 1 to 9999?
  • If the loop is a C for loop, is the loop header reserved for loop-control code?
  • Does the loop use begin and end or their equivalents to prevent problems arising from improper modifications?
  • Does the loop have something in it? Is it not empty?
  • Are housekeeping chores grouped, either at the beginning or the end of the loop?
  • Does the loop perform one and only one function, like a well-defined routine?
  • Does the loop end under all possible conditions?
  • Is the loop's termination condition obvious?
  • If the loop is a for loop, does the code inside it avoid monkeying with the loop index?
  • Is a variable used to save important loop-index values rather than using the loop index outside the loop?
  • Does the loop use safety counters, if you have a safety-counter standard?
  • If the loop is nested, does it use loop names for clarity?
  • Is the loop index an ordinal type or enumerated type?
  • Does the loop index have a meaningful name?
  • Does the loop avoid index cross talk?
  • Is the loop short enough to view all at once?
  • Is the loop nested to three levels or less?
  • If the loop is long, is it especially clear?