1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 15:00:38 +00:00
QB64-PE/internal/help/$IF.txt

68 lines
3.1 KiB
Plaintext
Raw Normal View History

2017-10-10 14:55:21 +00:00
'''$IF''' is precompiler [[Metacommand|metacommand]], which determines which sections of code inside its blocks are included into the final code for compliing.
2016-03-18 11:36:04 +00:00
{{PageSyntax}}
2017-10-10 14:55:21 +00:00
:[[$IF]] variable = expression THEN
:.
:[[$ELSEIF]] variable = expression THEN
:.
:[[$ELSE]]
:.
:[[$END IF]]
2016-03-18 11:36:04 +00:00
* $IF is the start of a precompiler code block which includes or excludes sections of code from being compiled.
2017-10-10 14:55:21 +00:00
* 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 statements in a single line is not allowed.'''
* 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 macOS 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.
2017-10-10 14:55:21 +00:00
* [[$END IF]] denotes the end of a valid precompiler $IF block.
* [[$ELSEIF]] must follow a valid $IF or $ELSEIF statement.
* If [[$ELSE]] is used, it must be used as the last conditional check before $END IF. $ELSEIF cannot come after $ELSE.
** There can only be one $ELSE in an '''$IF-$ELSEIF-$ELSE-$END IF''' block, and it must be the last block selection before the $END IF. $ELSEIF cannot follow $ELSE.
2016-03-18 11:36:04 +00:00
2017-10-10 14:55:21 +00:00
{{PageExamples}}
2016-03-18 11:36:04 +00:00
''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
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} "Hello World"
2016-03-18 11:36:04 +00:00
{{CodeEnd}}
2017-10-10 14:55:21 +00:00
''Explanation:'' The same CONST is defined twice inside the program. Normally, defining a CONST more than once generates an error, but the $IF condition here is choosing which CONST will be inside the final program.
2016-03-18 11:36:04 +00:00
2017-10-10 14:55:21 +00:00
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).
2016-03-18 11:36:04 +00:00
2017-10-10 14:55:21 +00:00
The [[$LET]] and $IF statements let the programmer control the code that actually gets compiled, while excluding the other blocks completely.
2016-03-18 11:36:04 +00:00
''Example 2:''
{{CodeStart}} '' ''
{{Cl|$IF}} WIN THEN
2019-04-15 01:15:33 +00:00
{{Cl|CONST}} Slash = "\"
2016-03-18 11:36:04 +00:00
{{Cl|$ELSE}}
2019-04-15 01:15:33 +00:00
{{Cl|CONST}} Slash = "/"
2016-03-18 11:36:04 +00:00
{{Cl|$END IF}}
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} "The proper slash for your operating system is "; Slash
2016-03-18 11:36:04 +00:00
{{CodeEnd}}
2017-10-10 14:55:21 +00:00
''Explanation:'' For the above, the CONST slash is defined by the automatic internal flags which returns what operating system is being used at compile time. On a Windows PC, the Slash will be the backslash; for any other OS it will be the forward slash.
2016-03-18 11:36:04 +00:00
2017-10-10 14:55:21 +00:00
{{PageSeeAlso}}
2016-03-18 11:36:04 +00:00
* [[$LET]]
2017-10-10 14:55:21 +00:00
* [[Metacommand]]s
2016-03-18 11:36:04 +00:00
2019-04-15 01:15:33 +00:00
{{PageNavigation}}
<