Others Commands


Syntax

Swap <expression>, <expression>
Description
Swaps the value of the both expression, in an optimized way. The both <expression> have to be a variable, array, list or a map element (structured or not) and have to be one of the SpiderBasic native type like long (.l), quad (.q), string etc.

Example: Swapping of strings

  Hello$ = "Hello"
  World$ = "World"
  
  Swap Hello$, World$
  
  Debug Hello$+" "+World$

Example: Swapping of multi-dimensional arrays elements

  Dim Array1(5,5) 
  Dim Array2(5,5) 
  Array1(2,2) = 10     ; set initial contents
  Array2(3,3) = 20
  
  Debug Array1(2,2) ; will print 10
  Debug Array2(3,3) ; will print 20
  
  Swap Array1(2,2) , Array2(3,3)  ; swap 2 arrays elements
  
  Debug "Array contents after swapping:"
  Debug Array1(2,2)    ; will print 20
  Debug Array2(3,3)    ; will print 10