Iterative programming

from Wikipedia, the free encyclopedia

The iterative programming (from lat. Iterare = repeat) is a concept in which multiple execute steps in loops (repetition of instructions or instruction sequences) are implemented.

Demarcation

Other programming concepts are

  • the recursion , the work to be performed for multiple steps recursion used (repeated self calls of a program part); in principle, recursive algorithms can also be implemented iteratively and vice versa.
  • the logic programming does not find the solutions to problems above instruction sequences, but logical through rule-based inference.

Juxtaposition

In the literature, functions are often presented in recursive programming style , which are usually considered to be easier to understand. However, iterative variants often have advantages:

  • In the case of iterative programming, the memory requirement can be tailored and controlled more precisely by the programmer, whereas in the case of recursive programming, the context of the calling procedure (in the program stack) must inevitably be saved with each self-call so that it can be restored on return .
  • In addition, the memory requirement for the program stack memory is difficult or impossible to control in programming language, which leads to the notorious stack overflows .
  • In recursive programming style, some scenarios can only by a so-called. Callback function ( English callbackFunction ) realize. For example, in the case of a recursively programmed traversing function of a binary tree, this is always run through in its entirety and the useful function is implemented in a callback.
    In contrast to this, with iterative programming, the segment of the tree to be processed can be controlled by a search function , the utility function can be implemented as a flat instruction sequence or as a subprogram and repeated after an (iterative) cross step for the next element.

example

An example of iterative programming is a database run ( Pascal ):

procedure Durchlauf;
begin
    while not Dataset.Eof do
    begin
        Befehl1;
        Befehl2;
        Befehl3;
        Dataset.Next;
    end;
end;

Commands 1 to 3 are repeated until all data records have been run through.

Notes and individual references

  1. See also Traversierung (with code examples) and Ben Pfaff: An Introduction to Binary Search Trees and Balanced Trees. Free Software Foundation, Inc. Boston 2004, p. 47 "4.9.2 Traversal by Iteration".