Back to table

Swap 2 variables

The following is valid µOCCAM. swap2var correctly swaps 2 variables without using an extra variable.

Program file: /public/cs3/web/ipptests/swap2var.accept
INT first = 3:
INT second = 5:

-- This has the effect of swapping the two variables

SEQ
  first := first + second
  second := first - second
  first := first - second