Navigation

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

    The non-logical "for" loop

    Coding
    11
    16
    1086
    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.
    • sys64738
      sys64738 F @Dave last edited by Martin

      @Dave

      Are arrays dynamic

      Array blip[10]
      blip[13] = 6
      Print(len(blip))
      

      Prints 13.

      It should be doing an out of bounds error shouldn't it. Doing the same with 2d array will go out of bounds

      Array blip[1][16]
      blip[1][16] =6
      //Print(len(blip))
      

      Errors. Attempted to index non-array type

      Array blip[1][16]
      blip[0][16] =6
      Print(len(blip))
      

      Prints 17?

      Array blip[1][16][76]
      blip[1][16][76] =6
      //Print(len(blip))
      

      Errors

      Array blip[1][16][76]
      blip[0][16][76] =6
      //Print(len(blip))
      

      Errors

      Array blip[1][16][76]
      blip[0][15][76] =6
      Print(len(blip))
      

      Prints 16?

      Honestly I have no idea what len a multi dimensional array is meant to say. But it seems to be odd. After looking how java does it blip[24][67] len(blip) should return 24

      Then there's the whole arrays saying they are the wrong type if a timers running. But fine if timers not running

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

        @sys64738 Edited your post to add code tags for you as it was very hard to read (impossible in the email notification)

        You can do so by using three of these before and after the code: `

        sys64738 1 Reply Last reply Reply Quote 1
        • sys64738
          sys64738 F @Martin last edited by

          @Martin said in The non-logical "for" loop:

          `

          thanks was wondering how to do that

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

            I've had a good look at this @sys64738 and this has uncovered an interesting bug. However, I think I should be able to smooth a couple of things over here:

            In Fuze, arrays are dynamic, but you can only dynamically expand one dimension at a time.

            In the first example,

            Array blip[10]
            blip[13] = 6
            Print(len(blip))
            

            This actually gives me 14, not 13. As expected, it has extended the array dimension successfully.

            In example two,

            Array blip[1][16]
            blip[1][16] =6
            //Print(len(blip))
            

            You are trying to expand two dimensions at ones. You'd have to do:

            array blip[1][16]
            blip[1] = []
            blip[1][16] = 6
            print( len( blip ) )
            

            The result should be a 2 if this is done. However, testing this has revealed a little bug where actually this gives us 17, the len() of blip[0].

            Same thing applies to more dimensions.

            Array blip[1][16][76]
            blip[0][16] = []
            blip[0][16][76] = 6
            //Print(len(blip))
            

            This result should give 2, but as mentioned before this results in 17.

            When you len() a multi dimensional array without specifying the dimension, you should get the len() of the first dimension.

            I've brought the bug to attention, thanks so much for the post.

            1 Reply Last reply Reply Quote 2
            • Zero Division
              Zero Division @Nisse5 last edited by

              @Nisse5 We could really use, at least, a forEach()

              1 Reply Last reply Reply Quote 0
              • H
                hengp9090 last edited by

                I was ran into somthing similar.
                I am a programmer, have some c/java backgrounds. I found "for loop" in fuze is very counter-intuitive until I accepted that fuze is a different programming language
                // 10 is excluded for i = 0 to 10 loop // 0 is included for i = 10 to 0 loop // the loop body will be skipped for i = 0 to 0 loop
                think about the code below
                for i = 10 to 0 loop for j = i - 1 to 0 loop print("Hello") repeat repeat
                if j evals to 0, the print statement will be skipped which causes some counter-intuitive results

                1 Reply Last reply Reply Quote 1
                • Zero Division
                  Zero Division last edited by

                  I'm kind of curious if the design of the for-loop in FUZE is influenced by some language I didn't use. BBC BASIC maybe? I found it counter-intuitive as well, but it's easy enough to adapt to. It seems the only utility of it is to be able to avoid saying "-1" a lot when iterating over arrays. I'm hoping eventually we get some kind of forEach() function/keyword, so we don't have to worry about array indexes at all (e.g. ...)

                  forEach i in someArray loop
                      doStuffWith( i )
                  repeat
                  1 Reply Last reply Reply Quote 0
                  • spikey
                    spikey F @Discostew last edited by

                    @Discostew just felt into that trap. For FUZE I feel like "for 1 to 10", should show 1 to 10 and "for 10 to 0" should show 10 to 0. Its like "spoken language".

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

                      @spikey If it were meant to be like BASIC, then I'd agree. But the FUZE team have different ideas. In this case, they made it more like C and other such languages. Even the HELP section points out how the loop is not supposed to execute with the ending index value. I prefer it this way because of the major use of everything being base-0, so I can start at base 0 element of things like arrays, and end the loop as if it were the number of times to iterate.

                      pianofire 1 Reply Last reply Reply Quote 1
                      • pianofire
                        pianofire Fuze Team @Discostew last edited by

                        @Discostew This was the reason. Anyway I think that we are committed now without breaking everyone's programs

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