This is an experimental feature that may change in future versions.
It is provided for compatibility with the Windows version of BBC BASIC and to enhance the code readibility of the Z80 version.
A statement which swaps (exchanges) the contents of two variables. The variables must be of the same type, for example two integer numeric variables or two strings. If the types differ, a Type mismatch error will result.
SWAP a,b SWAP Coat$,Hat$ SWAP array%(3),array%(4) SWAP buffer!0,buffer!4
Be very careful when swapping fixed strings that there is sufficient storage for both strings. For example, the following code
DIM tiny 4 : $tiny="Tiny" DIM gigantic 8 : $gigantic="Gigantic" SWAP $tiny,$gigantic
will try and swap the string 'Gigantic' (9 bytes including its CR terminator) into a memory location where only five bytes were allocated.
- SWAP <n-var>,<n-var>
- SWAP <s-var>,<s-var>