Search code examples
booleanterminologyboolean-expression

What's the word for a boolean and statement stopping if the first returns false?


Sorry the title isn't descriptive, but if I could describe it well I probably would've found my answer.

In Python, if you were to run the following:

def fun1():
    print("fun1 runs")
    return False

def fun2():
    print("fun2 runs")
    return True

x = fun1() and fun2()

It would print the statement

fun1 runs

because after fun1 returns False, x will be false regardless of what fun2 is so fun2 never runs.

What's the word for this? I ask because I wanted to search if PHP boolean expressions do the same thing but didn't know what it was called.

Sorry for asking a silly question about terminology, but it's been bugging me!


Solution

  • if I got you right then you are talking about short-circuit evaluation