In computing, a continuation represents the rest of the computation given a point in the computation. Another word for "rest of the computation" is control state, meaning the data structures and code needed to complete a computation: a continuation is an abstraction for the program's state and the to-be-executed instructions. Most languages implement the data structure as a variant of the stack and the code as just a pointer to the current instructions. There are also programming languages that represent the control data as a heap-allocated object.
Almost all programming languages have means for manipulating the continuation of a computation step. Early imperative languages provided the "goto" feature (in different guises, e.g. setjmp in C), which would force the computation to continue at some designated label. In the 1970s, people supplemented "goto" with additional control constructs that encapsulated frequently repeated control patterns. Simple examples are function returns, loop exits, and loop iteration breaks. Complex examples include Simula 67'scoroutines, Icon'sgenerators, Prolog's backtracking mechanism, and threads.
Only a few programming languages provide full, unrestrained access to the continuation of a computation step. Scheme was the first full production system, providing first "catch" and then call-with-current-continuation. Bruce Duba, an Indiana-University–trained Schemer who held a post-doctoral position at Bell Labs, introduced them into SML of New Jersey. Some Smalltalk and Python implementations provide similar access to continuations, though nothing as systematic as Scheme.
These models rely on programmers or semantics engineers to write mathematical functions in the so-called continuation-passing style. This means that each function consumes a function that represents the rest of the computation relative to this function call. To return a value, the function calls this "continuation function" with a return value; to abort the computation it returns a value.
Functional programmers who write their programs in continuation-passing style gain the expressive power to manipulate the flow of control in arbitrary ways. The cost is that they must maintain the invariants of control and continuations by hand, which is a highly complex undertaking.
One area that has seen practical use of continuations is in Web programming. The use of continuations shields the programmer from the stateless nature of the  protocol. In the traditional model of web programming, the lack of state is reflected in the program's structure, leading to code constructed around a model that lends itself very poorly to expressing computational problems. Thus continuations enable code that has the useful properties associated with inversion of control, while avoiding its problems. Inverting back the inversion is a paper that provides a good introduction to continuations applied to web programming.
Unlambda: c, the flow control operation for call with current continuation
Pico: call(exp()) and continue(aContinuation, anyValue)
In any language which supports closures, it is possible to write programs in continuation passing style and manually implement call/cc. This is a particularly common strategy in Haskell, where it is easy to construct a "continuation passing monad" (for example, the Cont monad and ContT monad transformer in the mtl library).
Kinds of continuations
Support for continuations varies widely. A programming language supports re-invocable continuations if a continuation may be invoked repeatedly (even after it has already returned). Re-invocable continuations were introduced by Peter J. Landin using his J (for Jump) operator that could transfer the flow of control back into the middle of a procedure invocation. Re-invocable continuations have also been called "re-entrant" in the MzScheme programming language. However this use of the term "re-entrant" is too easily confused with its use in discussions of multithreading.
At one time Gerry Sussman and Drew McDermott thought that using re-invocable continuations (which they called "Hairy Control Structure") was the solution to the AI control structure problems that had originated in Planner. Carl Hewittet al. developed message passing as an alternative solution in the Actor model. Guy Steele and Gerry Sussman then developed the continuations in Scheme in their attempt to understand the Actor model.
A more limited kind is the escape continuation that may be used to escape the current context to a surrounding one. Many languages which do not explicitly support continuations support exception handling, which is equivalent to escape continuations and can be used for the same purposes. C's setjmp/longjmp are also equivalent: they can only be used to unwind the stack. Escape continuations can also be used to implement tail-call optimization.
Continuations are the functional expression of the GOTO statement, and the same caveats apply. While many believe that they are a sensible option in some special cases such as web programming, use of continuations can result in code that is difficult to follow. In fact, the esoteric programming languageUnlambda includes call-with-current-continuation as one of its features solely because of its resistance to understanding. The external links below illustrate the concept in more detail.
Peter Landin. A Generalization of Jumps and Labels Report. UNIVAC Systems Programming Research. August 1965. Reprinted in Higher Order and Symbolic Computation, 11(2):125-143, 1998, with a foreword by Hayo Thielecke.
Drew McDermott and Gerry Sussman. The Conniver Reference Manual MIT AI Memo 259. May 1972.
Daniel Bobrow: A Model for Control Structures for Artificial Intelligence Programming Languages IJCAI 1973.
Carl Hewitt, Peter Bishop and Richard Steiger. A Universal Modular Actor Formalism for Artificial Intelligence IJCAI 1973.
Christopher Strachey and Christopher P. Wadsworth. Continuations: a Mathematical semantics for handling full jumps Technical Monograph PRG-11. Oxford University Computing Laboratory. January 1974. Reprinted in Higher Order and Symbolic Computation, 13(1/2):135--152, 2000, with a foreword by Christopher P. Wadsworth.
John Reynolds. Definitional Interpreters for Higher-Order Programming Languages Proceedings of 25th ACM National Conference, pp. 717-740, 1972. Reprinted in Higher-Order and Symbolic Computation 11(4):363-397, 1998, with a foreword.
John Reynolds. On the Relation between Direct and Continuation Semantics Proceedings of Second Colloquium on Automata, Languages, and Programming. LNCS Vol. 14, pp. 141-156, 1974.
Gerald Sussman and Guy Steele. SCHEME: An Interpreter for Extended Lambda Calculus AI Memo 349, MIT Artificial Intelligence Laboratory, Cambridge, Massachusetts, December 1975. Reprinted in Higher-Order and Symbolic Computation 11(4):405-439, 1998, with a foreword.
Robert Hieb, R. Kent Dybvig, Carl Bruggeman. Representing Control in the Presence of First-Class Continuations Proceedings of the ACM SIGPLAN '90 Conference on Programming Language Design and Implementation, pp. 66-77.
Will Clinger, Anne Hartheimer, Eric Ost. Implementation Strategies for Continuations Proceedings of the 1988 ACM conference on LISP and Functional Programming, pp. 124-131, 1988. Journal version: Higher-Order and Symbolic Computation, 12(1):7-45, 1999.