In functional programming, continuation-passing style (CPS) is a style of programming in which control is passed explicitly in the form of continuation function(s).
In CPS, in addition to receiving arguments as usual, each function also receives an additional function to be used as a continuation, so that instead of being returned as usual, a value is rather passed to this continuation function, as the function's final act.
Continuation functions are not expected to return in a normal sense, but rather return their values in the same manner, by further calling other continuation functions.
A computation either simply calls its continuation function, or constructs a new, more complex one, to express more complex patterns of computation, like recursion, or iteration.
Sometimes more than one continuation are used for each call, as e.g. with two continuations, one for a "successful" computation, another for a "failed" one.
Example:
nlog(n, x, onSuccess, onFailure) = (* iterated logarithm *)
onFailure(x) , if x <= 0 or n < 0
onSuccess(x) , if n == 0
onSucess(log(x)) , if n == 1
nlog(n-1, x,
x => onSuccess(log(x)), (* new success continuation constructed *)
onFailure (* same failure continuation *)
) , otherwise