Navigation

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

    Breaking out of a FOR loop causes one last increment of the variable used

    Bug Reporting (FUZE 4 Nintendo Switch)
    4
    6
    255
    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.
    • Discostew
      Discostew F last edited by Discostew

      u = 0
      for u = 0 to 5 loop
         if u == 2 then
            break
         endIf
      repeat
      print( u )
      update()
      sleep(10)
      
      -- prints 3 when it should still be 2 --
      

      This code allows the variable that is used by the FOR loop to be kept once outside of it for means of other uses. In other languages, doing this would retain the variable at the value last assigned to it before it broke out of the loop. With FUZE, it breaks out, but then increments the variable by one. This is unfortunately causing a bit of issue with my coding.

      1 Reply Last reply Reply Quote 4
      • Dave
        Dave Fuze Team last edited by

        Thank you Stew this is super valuable.

        1 Reply Last reply Reply Quote 0
        • Martin
          Martin Fuze Team last edited by Martin

          Just in case it's not obvious to anyone reading this, the workaround is to decrement the variable before exiting the loop so it becomes this:

          u = 0
          for u = 0 to 5 loop
             if u == 2 then
                  u -= 1
                break
             endIf
          repeat
          
          print( u )
          update()
          sleep(10)
          
          pianofire 1 Reply Last reply Reply Quote 2
          • pianofire
            pianofire Fuze Team @Martin last edited by

            @Martin That's fine until it is fixed and breaks again!

            1 Reply Last reply Reply Quote 1
            • Martin
              Martin Fuze Team last edited by

              Yep, so obviously it's a temporary workaround

              1 Reply Last reply Reply Quote 1
              • Discostew
                Discostew F last edited by

                I believe this was fixed in this most recent patch. Yay!

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