HOME

TheInfoList



OR:

Zahn's construct in
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, also known as the "situation case statement", 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 '' ...
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 Case or CASE may refer to: Instances * Instantiation (disambiguation), a realization of a concept, theme, or design * Special case, an instance that differs in a certain way from others of the type Containers * Case (goods), a package of relate ...
-like construct surrounding the loop.
Donald Knuth Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist and mathematician. He is a professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of comp ...
, 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 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 In computer science, a call stack is a Stack (abstract data type), stack data structure that stores information about the active subroutines and block (programming), inline blocks of a computer program. This type of stack is also known as an exe ...
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 In computer science, a preprocessor (or precompiler) is a Computer program, program that processes its input data to produce output that is used as input in another program. The output is said to be a preprocessed form of the input data, which i ...
.


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 federally funded research and development center in Menlo Park, California, United States. Founded in 1962, the laboratory is now sponsored ...
Pub-1530, January 1975
Control structures
defined using Scheme; Zahn's construct is the last one in the list
Zahn's construct
defined using GOTOs in Forth
The SKOL Programming Language Reference Manual
Control flow