HOME

TheInfoList



OR:

Zahn's construct, in
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, was a proposed structure for structured
control flow In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an ''imper ...
in computer programming languages first described by
Charles T. Zahn Charles is a masculine given name predominantly found in English and French speaking countries. It is from the French form ''Charles'' of the Proto-Germanic name (in runic alphabet) or ''*karilaz'' (in Latin alphabet), whose meaning was "f ...
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 following the loop. Donald Knuth, in his paper "Structured Programming with Go To Statements",Knuth, D. E
"Structured Programming with Go To Statements"
{{Webarchive, url=https://web.archive.org/web/20131023061601/http://cs.sjsu.edu/~mak/CS185C/KnuthStructuredProgrammingGoTo.pdf , date=2013-10-23 , ''Computing Surveys'', Volume 6, December 1974, page 275
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 ,J= target then found; missing; exits found: print ("item is in table"); missing: print ("item is not in table"); endexit;
Try-catch block In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
s, used in modern programming languages for
exception handling In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
, are variations 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 In computer science, a call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, program stack, control stack, run-time stack, or ma ...
and "caught" at a point higher up in the stack.


References


External links

* Zahn, C. T
Structured Control in Programming Languages
SLAC SLAC National Accelerator Laboratory, originally named the Stanford Linear Accelerator Center, is a United States Department of Energy National Laboratory operated by Stanford University under the programmatic direction of the U.S. Departm ...
Pub-1530, January 1975
Control structures
defined using
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
; Zahn's construct is the last one in the list
Zahn's construct
defined using GOTOs in
Forth Forth or FORTH may refer to: Arts and entertainment * ''forth'' magazine, an Internet magazine * ''Forth'' (album), by The Verve, 2008 * ''Forth'', a 2011 album by Proto-Kaw * Radio Forth, a group of independent local radio stations in Scotla ...
Control flow