Search code examples
basic

Why x = y = z does not return false


I have a piece of code that compares three values each defaulting to zero but it does not return false:

x = 0 : y = 0 : z = 0
IF x = y = z THEN PRINT "false"

and I cannot figure out why?


Solution

  • In older dialects of BASIC the following assigned all variables to zero:

    a = b = c = 0
    

    but after that each variable has to be set separately:

    a = 0 : b = 0 : c = 0
    

    then instead of comparing all values to zero, they were compared in boolean fashion between each: a=b=c would calculate a=b first then its value compared to c..