Iteration Articles about
Iteration
 

Information About

Iteration




The word ''iteration'' is sometimes used in everyday English with a meaning virtually identical to ''repetition''.


MATHEMATICS

Iteration in mathematics is the technique used in Iterative Method s, described in a separate article.


COMPUTING

Iteration in computing is the repetition of a Process within a Computer Program . It can be used both as a general term, synonymous with repetition, and to describe a specific form of repetition with a Mutable state.

When used in the first sense, Recursion is an example of ''iteration'', but typically using a ''recursive notation'', which is typically not the case for ''iteration''.

However, when used in the second (more restricted) sense, iteration describes the style of programming used in imperative programming languages. This contrasts with recursion, which has a more declarative approach.

Here an example of iteration, in imperative Pseudocode :

var i, a := 0 ''// initialize a before iteration''
for i '''from''' 1 '''to''' 3 { ''// loop three times''
a := a + i ''// increment a by the current value of i''
}
print a ''// the number 6 is printed''

In this program fragment, the value of the variable ''i'' changes over time, taking the values 1, 2 and 3. This changing value—or ''mutable state''—is characteristic of iteration.

Iteration can be approximated using recursive techniques in Functional Programming Language s. The following example is in Scheme . Note that the following is recursive (a special case of iteration) because the definition of "how to iterate", the iter function, calls itself in order to solve the problem instance:

(define (sum n)
(define (iter n i)
(if (= n 1)
i
(iter (- n 1)(+ n i))
))
(iter n 1))


An Iterator is an object that wraps iteration.


SEE ALSO