RosettaCodeData/Task/Short-circuit-evaluation/FreeBASIC/short-circuit-evaluation.basic

30 lines
619 B
Plaintext

' FB 1.05.0 Win64
Function a(p As Boolean) As Boolean
Print "a() called"
Return p
End Function
Function b(p As Boolean) As Boolean
Print "b() called"
Return p
End Function
Dim As Boolean i, j, x, y
i = False
j = True
Print "Without short-circuit evaluation :"
Print
x = a(i) And b(j)
y = a(i) Or b(j)
Print "x = "; x; " y = "; y
Print
Print "With short-circuit evaluation :"
Print
x = a(i) AndAlso b(j) '' b(j) not called as a(i) = false and so x must be false
y = a(i) OrElse b(j) '' b(j) still called as can't determine y unless it is
Print "x = "; x; " y = "; y
Print
Print "Press any key to quit"
Sleep