Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Logical and/or do not short-circuit

    Bug Reporting (FUZE 4 Nintendo Switch)
    2
    2
    240
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sahara-min
      sahara-min last edited by

      a = foo() and bar()
      sleep(2)
      
      function foo()
          print("foo")
      return false
      
      function bar()
          print("bar")
      return false
      

      I expected this little program to print "foo", but it actually prints "barfoo".
      Looks like 'and' evaluates its operands right to left and does not short-circuit evaluation when the first operand evaluates to false. I don't know if this is a bug but it's a bit different from how logical operations usually work in other languages.

      Spacemario 1 Reply Last reply Reply Quote 2
      • Spacemario
        Spacemario F @sahara-min last edited by Spacemario

        @sahara-min I once ran into a bug in my game, and it was due to me assuming operators short-circuit, which they weren't. I re-wrote the single if statement into a nested one, and my bug went away.

        So I think you're on to something here :D

        1 Reply Last reply Reply Quote 1
        • First post
          Last post