'''$IF''' is precompiler command, which determines which sections of code inside its blocks are included into our code for compliing.


{{PageSyntax}}
:: $IF variable = expression THEN...
::.
::.
::.
:: $END IF


* $IF is the start of a precompiler code block which includes or excludes sections of code from being compiled.
* Currently there is no single line $IF statement.  $IF must be in a valid $IF THEN...   $END IF block to work properly.
* Like all other metacommands, you can not use more than one metacommand per line.  Use of : to separate multi-line statements onto one line will not work with $IF (or any other metacommand).
* Variable names can contain numbers, letters, and periods -- in any order!   
* Expressions can contain one set of leading and/or trailing quotes; and any number of numbers, letters, and periods, in any order.
* The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude for us.  These are: '''WIN''' or '''WINDOWS''' if the user is running QB64 in a windows environment.  '''LINUX''' if the user is running QB64 in a Linux environment.  '''MAC''' or '''MACOSX''' if the user is running QB64 in a Mac environment.  '''32BIT''' if the user is running a 32-bit version of QB64.  '''64BIT''' if the user is running a 64-bit version of QB64.



''Example 1:'' 
{{CodeStart}} '' ''
{{Cl|$LET}} ScreenMode = 32
{{Cl|$IF}} ScreenMode = 0 THEN
    {{Cl|CONST}} Red = 4
{{Cl|$ELSEIF}} ScreenMode = 32 THEN
    {{Cl|CONST}} Red = _RGB32(255,0,0)
{{Cl|$END IF}}

{{Cl|COLOR}} Red
{{Cl|PRINT}} &quot;Hello World&quot;
{{CodeEnd}}

Explanation:
If you look at the code above, you'll see that we have the same CONST defined twice inside the program.  Normally, we get an error if we try to define a CONST more than once, but the $IF condition here is CHOOSING which CONST we want inside our program.

AS long as Screenmode is 0, the program will exclude the code where CONST Red is defined as color 4.  If Screenmode is 32, CONST Red will be defined as _RGB32(255, 0, 0).

The $LET and $IF statements let us control the code that actually gets compiled, while excluding the other blocks completely.



''Example 2:'' 
{{CodeStart}} '' ''
{{Cl|$IF}} WIN THEN
    {{Cl|CONST}} Slash = &quot;\&quot;
{{Cl|$ELSE}}
    {{Cl|CONST}} Slash = &quot;/&quot;
{{Cl|$END IF}}

{{Cl|PRINT}} &quot;The proper slash for your operating system is &quot;; Slash
{{CodeEnd}}

For the above, the CONST slash is defined by the automatic internal flags which tell us what operating system we're using.  On a windows PC, the Slash will be the backslash; for any other OS it will be the forward slash.


''See also:'' 
* [[$LET]]
* [[$ELSE]]
* [[$ELSEIF]]
* [[$END IF]]

{{PageNavigation}}