Syntax
Swaps two elements of a list, given by their positions.
SwapElements(<list>(), <first>, <second>)Parts
| <list> | A list declared with NewList, written with its empty parentheses: scores(). |
|---|---|
| <first> | The position of one element, from 0. Decimals are dropped. |
| <second> | The position of the other element, from 0. Decimals are dropped. |
Good to know
- Returns nothing: write it on its own line.
- The current element stays the same element, so its position can change: in the example it follows the 1 to position 2.
- A position outside the list stops the program with "SwapElements index is out of bounds".
- Coming from PureBasic: the two elements are positions, not element pointers.
Example
NewList a.integer()FOR k = 1 TO 3 AddElement(a()) a() = kNEXTFirstElement(a())SwapElements(a(), 0, 2)Console(Str(a()) + " at " + Str(ListIndex(a()))) ' 1 at 2FOREACH a() Console(Str(a())) ' 3, 2, 1NEXTIn the manual : Arrays, lists and maps