GLBasic User Manual

Main sections

AND

a# = b# AND c#



Logical AND connections. They return TRUE or FALSE.
(See bAND for Binary AND)

AND:
returns TRUE if both (b# and c#) are non zero.

Attention:
AND and OR follow the GLBasic operator-style and evaluate from left to right if no brackets are used.

    istwo = 2
    isthree = 3
    isfour = 4

    IF (istwo = 2) AND (isthree = 3)
        // Will print as both conditions are true (i.e. 1)
        // AND needs both conditions to be true
        PRINT "istwo = 2 and isthree = 3",0,0
    ENDIF

    IF (istwo = 2) AND (isthree = 2)
        // This wont print as second condition is false (i.e. 0)
        // AND needs both conditions to be true

        PRINT "isone = 1 and istwo = 1",0,10
    ENDIF

    IF (istwo = 4) OR (isthree = 3)
        // Will print as only one condition needs to be true (i.e. 1) for an OR condition
        PRINT "isone = 1 and istwo = 2",0,20
    ENDIF

    IF ((isthree = 6) AND (isfour = 4)) OR (istwo = 2)
        // ((isthree = 6) and (isfour = 4)) = FALSE
        // (istwo = 2) = TRUE
        // FALSE "OR" TRUE = TRUE therefore this will print
        PRINT "((isthree = 6) AND (isfour = 4)) or (istwo = 2)",0,30
    ENDIF

    SHOWSCREEN
    MOUSEWAIT


Output:
istwo = 2 and isthree = 3

isone = 1 and istwo = 2
((isthree = 6) AND (isfour = 4)) or (istwo = 2)

See also...