SwapIfLower
SwapIfLower NumericVar1, NumericVar2
 
Parameters:

    NumericVar1 = first numeric variable
    NumericVar2 = second numeric variable
Returns: NONE
 

     SwapIfLower performs a conditional swap betweem two numeric variables. SwapIfLower checks If NumericVar1 is lower than NumericVar2, if so, it swaps the contents of the two variables. if not, they are left unchanged.

     If the data typse of both variables are not the same, PlayBASIC will cast them automatically. So you can swap between an Integer and Float variables, But that's not recommended.



FACTS:


      * SwapIfLower cannot use string variables.


      * SwapIfLower performs a conditional exchange between two variables, so it's short hand for the following.

  
; check if A is less  than B. If so, perform swap them.
  If A<B
   ; Do swap
     Temp=A    ; Store A in a temp varibale
     A=B  ; Move the value in B into A Variable
     B=Temp   ; Move the Temp Variable into Temp
  EndIf
  


is the same as,

  
; Do swap
  SwapIfLower A,B
  





Mini Tutorial:




  
; define two variables
  a = 10
  b = 100
  
; swap a and b if a is less than b
  SwapIfLower a,b
  
; print the variables
  Print a
  Print b
  
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  




This example would output.

  
  100
  10
  

 
Related Info: If | Swap | SwapIfHigher :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com