SwapIfHigher
SwapIfHigher NumericVar1, NumericVar2
 
Parameters:

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

     SwapIfHigher performs a conditional swap betweem two numeric variables. SwapIfHigher checks If NumericVar1 is greater 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:


      * SwapIfHigher cannot use string variables.


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

  
; check if A is bigger then 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
  SwapIfHigher A,B
  








Mini Tutorial:




  
; define two variables
  a = 55
  b = 5
  
; swap a and b if a is greater 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.

  
  5
  55
  

 
Related Info: Float | If | Integer | Swap | SwapIfLower | Variables :
 


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