Not expression
Parameters
| expression - the value or condition to invert |
Description
|
Returns 1 when the expression is zero, and 0 when it is anything else. Not is a logical inversion, written in front of its expression: While Not KeyDown(1) is the standard Blitz main loop, running until Escape is pressed. It is worth being precise about what it does, because the name suggests otherwise. Not tests against zero and hands back 1 or 0 - nothing more. Not 0 is 1, Not 1 is 0, and Not 5 is also 0, because 5 is not zero. It does not flip the bits of a value: Not 5 is 0, not -6. When you want every bit inverted, use the unary complement operator ~ instead, or Xor with -1. Not binds looser than everything except And, Or and Xor, so Not a=b tests whether the whole comparison failed rather than comparing Not a with b. Bracket where you want to be explicit. Typical uses: While Not finished, If Not IsAlive(e) Then Respawn e, and testing a type handle with If Not p, which is true when p is Null. See also: And, Or, Xor, If, While. |
Example
; Not Example ; ----------- ; Not flips a condition: true becomes false, false becomes true. ; Its most common home is a main loop - While Not KeyDown(1) - or ; checking that something has NOT happened yet. game_over=False ; game_over is false, so Not game_over is true If Not game_over Then Print "Game on! (game_over is false)" EndIf Print "" ; Not treats 0 as false and any other value as true Print "Not 0 = "+(Not 0) Print "Not 1 = "+(Not 1) Print "Not 5 = "+(Not 5)+" (any non-zero value counts as true)" Print "" ; Combined with a comparison lives=0 If Not lives>0 Then Print "No lives left - game over." Print "" Print "Press any key to close the example" WaitKey End
Index