Termination condition

from Wikipedia, the free encyclopedia

In computer science, a termination condition is a condition that must be met in order for a process to be terminated. Every loop or recursive function therefore needs a termination condition if it is not to run indefinitely.

However, the existence of a termination condition does not guarantee termination: it is necessary , but not sufficient . Errors in the specification of the loop or the recursive function, as well as inputs that do not correspond to the specification, can make the termination condition unsatisfiable. In this case an infinite loop is created . However, it does not require any unsatisfactory termination conditions to allow loops to run indefinitely.


In the following function (syntax of C ++ or Java ) the marked line represents the termination condition; if this is fulfilled, the recursive descent is ended:

int zweiHoch(int i)
  if (i == 0)
     return 1; // zwei hoch 0 ist 1
     return 2*zweiHoch(i-1); // zwei hoch i ist zwei mal (zwei hoch i-1)

If you call the function with values ​​greater than or equal to 0, you get the corresponding power of two. Although the termination condition can be fulfilled, the recursion continues indefinitely if a negative parameter is passed.

See also


  • Wolfgang Schneider: Structured programming in BASIC. Friedrich Vieweg & Sohn Verlagsgesellschaft, Wiesbaden 1985, p. 256 ff.
  • Cornelia Heinisch, Joachim Goll, Frank Müller: Java as the first programming language. 4th edition, BG Teubner Verlag, Wiesbaden 2005, ISBN 3-519-32642-6 , p. 286 ff.

Web links

Wiktionary: Termination condition  - explanations of meanings, word origins, synonyms, translations