#IF
#IF <..expression..>
 
Parameters: NONE
Returns: NONE
 

      #IF is as compile time decisional directive. It allows you selectively compile sections of code that can be compiled, or ignored. #IF is used in conjunction with the #ELSE and #ENDIF statements.

      The #IF/#ELSE/#ENDIF work the same as IF/ELSE/ENDIF commands, the difference being that directives are evaluated during compilation and not run time.

      Since #if directives are evaluated during compilation. They can only work upon expressions contain constants. A common use of #IF directives is for including or removing Test/Debug code from your program.





#IF/#ENDIF


      The pairing of the #IF/#ENDIF directives, provides a multi line compile time comparison. This allows for lines of code (blocks of code) to be selectively compiled, depending upon the condition of the #IF expression. If the expression is TRUE(1), the compiler will compile the code within the #IF/ #ENDIF pair. If NOT, it'll skip over it completely.


Example
  
  
  Constant SpecialDay$ = "Nov"
  
  #IF  SpecialDay$="Nov"
     Print "Yay, my birthday is this month!"
  #ENDIF
  
  Sync
  WaitKey
  
  




#IF/#ELSE/#ENDIF


      Previously with the #IF/#ENDIF we've only been able to selectively compile one section code when the #IF expression is TRUE. However some times you need to selectively choose between two sections of code to compile. With the #ELSE directive, we gain this control.

      Depending upon if the #IF expression is TRUE OR FALSE, determines which section of code is compiled. So logically, when the #IF condition is TRUE(1), the code between the #IF and #ELSE directives is compiled. But when #If the condition is FALSE(0), the code after the matching #ELSE and the closing #ENDIF is compiled.


Example.

  
  
  Constant Mode = 0
  
  #IF  Mode=0
     Print "This Program Was compiled in Mode Zero"
  #ELSE
     Print "This Program Was compiled in some other Mode"
  #ENDIF
  
  Sync
  WaitKey
  
  


      This example would display (bellow), since the condition (Mode = 0) is True (Mode does equal 0). Notice how the code between the #ELSE/#ENDIF is not compiled. So only the code between the #IF/#ELSE will exist in the compiled program.

  
  This Program Was compiled in Mode Zero
  




 
Related Info: #ENDIF | #IFDEF | #IFNDEF | Comparisons | Limitations :
 


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