Tutorial: Boolean Expressions
This tutorial will introduce you to boolean expressions.
What is a Boolean Expression?
A boolean expression is any expression that evaluates to either True or False.
The two most simple boolean expressions are : True and False.
Boolean expressions are used to by conditional statements and loops to make decisions.
For example :
If True Then Print "This boolean expression is true, so If displayed this."
Sync
WaitKey
Variables can also be used :
boolExp = True
If boolExp Then Print "This boolean expression is true, so If displayed this."
Sync
WaitKey
Data Types as Boolean Expressions
Numbers as Boolean Expressions
As boolean expressions, the only number that is false is 0.
Every other number is true.
If 1 Then Print "1 is 'True', so this was displayed."
If 0 Then Print "You'll never see this."
If -1 Then Print "-1 is also 'True'."
Sync
WaitKey
Many functions return either a 1 or 0 and therefore can be said to return boolean expressions.
SetFPS 60
Do
Cls 0
Print "SpaceKey() currently returns: " + Str$( SpaceKey() )
If SpaceKey() Then Print "SpaceKey() returns 1 when the Space Key is down, so it's True."
Sync
Loop
Strings as Boolean Expressions
Strings as boolean expressions are always False by themselves.
If "string!" Then Print "This string is False."
Print "Using a string by itself is always False "
Sync
WaitKey
Next Steps
| Categories: Beginner Tutorials : Programming Tutorials : Tutorials |