Monday, 29 September 2014

Iteration

Iteration?


  • The act of repeating a process with the aim of approaching a desired goal, target or result.
  • Each repetition of the process is also called an iteration, and the results of one iteration are used as the starting point for the next iteration.
  • Iteration is used to repeat sections of code.

Why would we use it?

  • Readability
  • Reducing number of lines in code.
  • More efficient || powerful.
  • More manageable.
  • Extensible with new features.

Count-Controlled?

  • Will repeat a fixed number of times based on limit and increment.
  • Good for arrays or when the number of repetitions is known in advance.

While loops?

  • Repeat until condition is true.
  • If the condition never fails it can run FOREVER.

Two variations?

  • While do: Condition comes first (evaluates upfront).
  • Do While: Condition comes last (will run once).

No comments:

Post a Comment