next up previous contents index
Next: A++ code of `while' Up: Imperative Programming in A++ Previous: Imperative Programming in A++   Contents   Index


The abstraction `while'

The following abstraction is used as a statement to be exectuted and is therefore an example of the imperative programming style. The DOWHILE-Construct as defined in Structured Programming is available in most programming languages to code loops in programs. In functional programming iterations are implemented as recursions. (Recursion is explained in patterns:recurse).

In such a loop construct lambda-abstractions are evaluated repeatedly for the purpose of the side-effects they produce. A variable is modified in the repeated block used to determine, whether the iteration should be stopped. This is obviously imperative programming.

It is remarkable, that such a 'while'-construct can be defined in A++ as a lambda-abstraction. In most of the other programming languages such an attempt would be in vain.

It should be noted however that all the statements to be repeated are bound together by one `lambda'. This is necessary because `while' is defined as a lambda-abstraction expecting two arguments. One argument stands for the condition that controls whether another iteration should occur and the second variable stands for the block to be repeated. The possibility to define lambda-abstractions with a variable number of arguments is not implemented in A++ right now.


next up previous contents index
Next: A++ code of `while' Up: Imperative Programming in A++ Previous: Imperative Programming in A++   Contents   Index
domain access counter Georg P. Loczewski 2004-03-05