RosettaCodeData/Task/Short-circuit-evaluation/BBC-BASIC/short-circuit-evaluation.basic

29 lines
910 B
Plaintext

REM TRUE is represented as -1, FALSE as 0
FOR i% = TRUE TO FALSE
FOR j% = TRUE TO FALSE
PRINT "For x=a(";FNboolstring(i%);") AND b(";FNboolstring(j%);")"
x% = FALSE
REM Short-circuit AND can be simulated by cascaded IFs:
IF FNa(i%) IF FNb(j%) THEN x%=TRUE
PRINT "x is ";FNboolstring(x%)
PRINT
PRINT "For y=a(";FNboolstring(i%);") OR b(";FNboolstring(j%);")"
y% = FALSE
REM Short-circuit OR can be simulated by De Morgan's laws:
IF NOTFNa(i%) IF NOTFNb(j%) ELSE y%=TRUE : REM Note ELSE without THEN
PRINT "y is ";FNboolstring(y%)
PRINT
NEXT:NEXT
END
DEFFNa(bool%)
PRINT "Function A used; ";
=bool%
DEFFNb(bool%)
PRINT "Function B used; ";
=bool%
DEFFNboolstring(bool%)
IF bool%=0 THEN ="FALSE" ELSE="TRUE"