Navigation

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

    'continue' command

    Beginners
    3
    6
    371
    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.
    • J
      Jack_Blue last edited by

      Hi,

      I want to use a while loop to keep checking through a nested list, checking that the it meets a set of criteria. If any one of these criteria are not met, I want to make changes to the nested list, then start the while loop again without executing the rest of the code in the loop. The problem is, to do this I need a 'continue' command, and there doesn't seem to be one!

      I understand that I can simulate a 'continue' command by making a few changes to my code.

      Take this example. This code loops through the list example_list replacing every 0 with a 1, with a 'continue' command being used to start the while loop again every time a substitution is made. The while loop is only broken out of once the last bit of code in the loop is executed - which requires all of the code in the loop to be executed without the loop being started again by a 'continue' command. This means that the loop will only be broken out of once every 0 in the list has been replaced by a 1.

       example_list = [1, 1, 0, 1, 1, 1, 0, 1, 0, 1]
       still_zeros = True
       while still_zeros loop
           carry_on = False
           for index = 0 to len(example_list) loop
               if example_list[index] == 0 then
                   example_list[index] == 1
                   carry_on = True
                   break //This breaks out of the for loop, but not the while loop
               endif
           repeat
           if carry_on then
               continue //This starts the while loop again
           endif
           still_zeros = False
       repeat
      

      This code can be altered to get rid of the 'continue' command, while still retaining the same functionality, if this simple change is made:

       example_list = [1, 1, 0, 1, 1, 1, 0, 1, 0, 1]
       still_zeros = True
       while still_zeros loop
           carry_on = False
           for index = 0 to len(example_list) loop
               if example_list[index] == 0 then
                   example_list[index] == 1
                   carry_on = True
                   break //This breaks out of the for loop, but not the while loop
               endif
           repeat
           if !carry_on then
               still_zeros = False
           endif
       repeat
      

      Basically, after the point at which changes might be made to the list, the rest of the code in the while loop is inside an if statement, and is only executed if no changes have been made to the list. If changes HAVE been made, all of that code gets skipped for the current iteration of the while loop (the same effect as if a 'continue' command were used).

      The problem is, while this approach works fine for simpler code, it quickly gets complicated if you have a loop that requires lots of uses of the 'continue' command, because every time you would use one, you instead have to paste the rest of the code (the stuff that a 'continue' command would skip) inside an if loop. This means that you can end up with lots and lots of loops!

      i guess what I'm asking is:

      (1) Is there a continue command, and I just can't find it in the list of commands?

      And if the answer is 'no'...

      (2) How do I petition for the continue command to be added to Fuze?

      1 Reply Last reply Reply Quote 0
      • J
        Jack_Blue last edited by

        I'm aware that each 0 in the list can be replaced by a 1 much more easily:

            example_list = [1, 1, 0, 1, 1, 1, 0, 1, 0, 1]
            for index = 0 to len(example_list) loop
                if example_list[index] == 0 then
                    example_list[index] == 1
                endif
            repeat
        

        However, my goal is to have a code that only makes ONE CHANGE with each iteration of the while loop, before starting the whole while loop again after each change is made (it's too complicated to explain why, that's just what my project needs).

        1 Reply Last reply Reply Quote 0
        • J
          Jack_Blue last edited by

          Just noticed, each time I wrote

              example_list[index] == 1
          

          it should actually have been

              example_list[index] = 1
          1 Reply Last reply Reply Quote 0
          • vinicity
            vinicity F last edited by vinicity

            Another idea might be to have one outer while loop and one inner while loop, and instead of continue you do break in the inner loop.

            If both loops have the same exit criteria, I would think they would be functionally identical to a single loop with continue .

            1 Reply Last reply Reply Quote 2
            • vinicity
              vinicity F last edited by vinicity

              But to answer your questions:

              (1) No, there is no continue command in Fuze.
              (2) The people developing Fuze do read the forum, and will likely make note of any suggestions made.

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

                Request for 'continue' duly noted - there's no petitioning for new features :)

                In the meantime:

                 example_list = [1, 1, 0, 1, 1, 1, 0, 1, 0, 1]
                 still_zeros = True
                 while still_zeros loop
                     for index = 0 to len(example_list) loop
                         if example_list[index] == 0 then
                             example_list[index] == 1
                             break //This breaks out of the for loop, but not the while loop
                         endif
                     repeat
                     // index will only get to equal len(example_list) if it
                     // got all the way through without finding any more zeros to replace
                     if index == len(example_list) then
                       still_zeros = false
                     endif
                 repeat
                

                I'm not at my switch at present but doesn't that simplify things somewhat?
                NB: If the loop isn't iterating over as you might expect try adding int index = 0 just before the for loop. It sounds counter-intuitive but Fuze has needed it up until now due to scoping issues. I haven't tested yet if that is still the case in the latest patch.

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