Iterative Software Code

From GM-RKB
Jump to navigation Jump to search

An Iterative Software Code is a software code that ...



References

2016

  • (Wikipedia, 2016) ⇒ https://en.wikipedia.org/wiki/iteration#Computing Retrieved:2016-7-25.
    • Iteration in computing is the repetition of a block of statements 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. Confusingly, it may also refer to any repetition stated using an explicit repetition structure, regardless of mutability.

      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.

      Used in the third sense, repetitions using while or for loops as well as those using map or fold functions may be considered iterations.

      Here is an example of iteration relying on destructive assignment, in imperative pseudocode:

               <P>        a = 0         <P>        for i from 1 to 3 // loop three times         <P>        {         <P>        a = a + i // add the current value of i to a         <P>        }         <P>        print a // the number 6 is printed (0 + 1; 1 + 2; 3 + 3)         <P>        

      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 languages. 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. Specifically it uses tail recursion so it does not use large amounts of stack space.

      <source lang="scheme">

      (let iterate ((i 1) (a 0))

      (if (<= i 3)

      (iterate (+ i 1) (+ a i))

      (display a)))

      </source>

      An iterator is an object that provides iteration as a generic service, allowing iteration to be done in the same way for a range of different data structures. Conversely, an iteratee is an abstraction which accepts or rejects data during an iteration process (controlled externally by an enumerator - so unlike with code that uses iterators, the iteratee code is not "in charge" of the iteration process).

      Iteration is also performed using a worksheet, or by using solver or goal seek functions available in Excel. Many implicit equations like the Colebrook equation can be solved in the convenience of a worksheet by designing suitable calculation algorithms. Many of the engineering problems like solving Colebrook equations reaches 8-digit accuracy in as small as 12 iterations and a maximum of 100 iterations is sufficient to reach a 15-digit accurate result.