True
Parameters
| None. |
Description
|
A built-in constant with the value 1, used to mean "yes" in a condition. True is a keyword, not a function, so it takes no brackets. It is a compile-time constant, which means writing True costs exactly as much as writing 1 - nothing. Use it to make intent obvious. found = True reads better than found = 1, Return True says clearly that a function succeeded, and Repeat ... Until done=True spells out the exit condition. Blitz3D+ comparisons also produce 1 for true and 0 for false, so a value you got from a comparison can be compared against True safely. There is a classic Blitz idiom worth knowing: Select True, followed by Case with full conditions in it, turns a long ladder of ElseIf tests into a tidy Select block, because each Case is compared against True. One caution: only treat a value as True when you set it yourself or got it from a comparison. Testing some_number = True is not the same as testing whether some_number is non-zero, since 5 = True is false. Write If some_number, or If some_number<>0, in that case. See also: False, If, Not, Select, While. |
Example
; True Example ; ------------ ; True is a built-in constant equal to 1. It makes flags and yes/no ; function results read naturally. Print "The value of True is "+True Print "" ; A flag set with True player_alive=True If player_alive Then Print "The player is alive." ; A function can answer a yes/no question by returning True or False If IsEven(10) Then Print "10 is even." If Not IsEven(7) Then Print "7 is odd." Print "" Print "Press any key to close the example" WaitKey End Function IsEven(n) ; Even numbers leave no remainder when divided by 2 If n Mod 2=0 Then Return True Return False End Function
Index