Others Commands


Syntax

Goto <label>
Description
This command is used to transfer the program directly to the labels position. Be cautious when using this function, as incorrect use could cause a program to crash...

Note: To exit a loop safely, you always must use Break instead of Goto, and never use it inside a Select/EndSelect block (Unless you have the ability to manage the stack yourself, correctly.)

Syntax

End [ExitCode]
Description
Ends the program execution correctly. The 'ExitCode' optional parameter can be specified if the program need to returns an error code (widely used in console programs).

The 'ExitCode' can be further used e.g. with the ProgramExitCode() command.

Syntax

Swap <expression>, <expression>
Description
Swaps the value of the both expression, in an optimized way. The both <expression> have to be a variable, an array element, a list element or a map element (structured or not) and have to be one of the PureBasic 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