Jump to content

Zahn's construct

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wws (talk | contribs) at 18:02, 21 July 2006 (More info). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Zahns Construct was a proposed structure for structured control flow in computer programming languages. The construct is primarily described in terms of an extension to looping constructs to recognise multiple means by which a loop could terminate. For example, a search loop might terminate early - when the target is found, or may terminate after the search has been completed unsuccessfully. Zahns construct can be used to avoid GO TO statements when determining which case was encountered. Zahn does this by introducing a new kind of variable called a situation indicator, then using this in a CASE-like construct following the loop.

Donald Knuth, in his classic paper Structured Programming with Go To Statements, describes two forms of Zahns construct as follows:

 loop until <situation 1> or ... or <situation n>:
   <statement list 0>
 repeat;
 then <situation 1> => <statement list 1>;
  ...
      <situation n> => <statement list n>;
 fi

and:

 begin until <situation 1> or ... or <situation n>:
   <statement list 0>;
 end;
 then <situation 1> => <statement list 1>;
  ...
      <situation n> => <statement list n>;
 fi

There must also be a statement to set a specific situation indicator and exit the body of the construct.

Try-catch blocks, used in modern programming languages for exception handling, are variations of Zahns construct. The major difference is that the scope of Zahns proposals were limited to individual loops within a program; whereas more extensive exception handling capabilities often allow exceptions to be 'thrown' deep in a call stack, and 'caught' at a point higher up in the stack.

References

  • Knuth, D. E. "Structured Programming with Go To Statements", Computing Surveys, Volume 6, December 1974
  • Zahn, C. T. "A control statement for natural top-down structured programming" presented at Symposium on Programming Languages, Paris, 1974.