Skip to content
Surf Wiki
Save to docs
general/control-flow

From Surf Wiki (app.surf) — the open knowledge base

Zahn's construct

Computer science concept


Computer science concept

Zahn's construct in computer science, also known as the "situation case statement", was a proposed structure for structured control flow in computer programming languages first described by Charles T. Zahn in 1974. The construct is primarily described in terms of an extension to looping constructs to recognize multiple means by which a loop could terminate. For example, a search loop might terminate early, when the target is found; or it might terminate after the search has been completed unsuccessfully. Zahn's 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 in a CASE-like construct surrounding the loop.

Donald Knuth, in his paper "Structured Programming with Go To Statements", describes two forms of Zahn's construct as follows:

loop until or ... or : repeat; then = ; ... = ; fi

and:

begin until or ... or : ; end; then = ; ... = ; fi

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

The following simple example involves searching a two-dimensional table for a particular item.

exitwhen found or missing; for I := 1 to N do for J := 1 to M do if table[I,J] = target then found; missing; exits found: print ("item is in table"); missing: print ("item is not in table"); endexit;

Try-catch blocks, used in modern programming languages for exception handling, are substantial extensions of Zahn's construct. The major difference is that the scope of Zahn's proposals were limited to individual loops within a program, whereas exception-handling capabilities often allow exceptions to be "thrown" from deep within a call stack and "caught" at a point higher up in the stack. Because Zahn's construct is local to a routine, it can be implemented very efficiently, without any need to 'unwind' the call stack.

Zahn implemented his situation case statement in his SKOL language. SKOL was implemented as a set of macros for the MORTRAN Fortran preprocessor.

References

References

  1. Zahn, C. T. [https://cds.cern.ch/record/414919/files/dd-74-6.pdf "A control statement for natural top-down structured programming"] presented at Symposium on Programming Languages, Paris, 1974.
  2. Knuth, D. E. [http://cs.sjsu.edu/~mak/CS185C/KnuthStructuredProgrammingGoTo.pdf "Structured Programming with Go To Statements"] {{Webarchive. link. (2013-10-23 , ''Computing Surveys'', Volume 6, December 1974, page 275)
Info: Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about Zahn's construct — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report