# Termination condition

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.

## example

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
else
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.