views:

394

answers:

2

I have this homework question about loops in general (if it make sense at all), it goes like this:

Describe the three elements that must be included in order for a loop to successfully perform correctly.

Any idea what they might be?

+7  A: 
  1. Initialisation.
  2. Condition.
  3. Increment.
Martin
woudn't 2 be more of an "exit condition"?
Radu094
@Radu: no - 2 is the continuation condition - you exit when it is no longer met.
Shane C. Mason
Increment can be rather misleading, a loop can perform decrement (though one might argue it's a -1 increment). For a `while` loop, increment/decrement isn't implicit.
o.k.w
+1  A: 

Riding on Martin's answer and assuming that a successful loop can be an infinite one, here's my rendition

  1. Initialisation
  2. Condition (e.g. check for early exit)
  3. Continuation
o.k.w