or (logical OR)

k = 0
for y in range(5, 95, 5):
    k += 1    
    if y > 45 or k % 2 == 0:
        # Set color to red for every other line when y <= 45
        # and all y > 45.
        stroke(color(255, 0, 0))
        stroke(0)    # Set color to black
    line(30, y, 80, y)

Compares two expressions and returns True if one or both evaluate to True. Returns False only if both expressions are False. The following list shows all possible combinations:

True or False   # Evaluates True because the first is True
False or True   # Evaluates True because the second is True
True or True    # Evaluates True because both are True
False or False  # Evaluates False because both are False

The "or" operator is short-circuiting; it will not bother to evaluate its second expression of the first is True. That means, in the following example, that DoSomething is never called:

def DoSomething():
    print "You will never see this message!"
    return True

x = True
if x or DoSomething():
    print "This always happens."
expression1 or expression2
expression1any valid expression
expression2any valid expression
Related && (logical AND)
not (logical NOT)

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.