Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Meta commands

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    31
    2.1k
    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.
    • jens55undefined
      jens55
      last edited by

      Here is another thing that strikes me as odd:

      while true
        if iterations < 10
          m118 s"hello world"
          g4 s2
          continue
        if iterations < 11
          m118 s"hello north america"
      	g4 s2
      	continue
        break
      

      This code will execute the first 'if' for 10 times but will not reset 'iterations' as I would have expected and because of that will only execute the second 'if' loop once.

      alankilianundefined 2 Replies Last reply Reply Quote 0
      • jens55undefined
        jens55 @OwenD
        last edited by

        @owend said in Meta commands:

        Your continue command is useless as it's not part of the while construct.
        The point of continue is to skip an iteration.

        To skip an iteration ???? Where did you see this in the documentation ???
        I look at 'continue' as a command that strictly exists as a means to improve readability of the code since the command itself seems to do diddly squat and can be left out.

        alankilianundefined DanS79undefined 2 Replies Last reply Reply Quote 0
        • alankilianundefined
          alankilian @jens55
          last edited by

          @jens55 said in Meta commands:

          @owend said in Meta commands:

          Your continue command is useless as it's not part of the while construct.
          The point of continue is to skip an iteration.

          To skip an iteration ???? Where did you see this in the documentation ???

          'continue' jumps back to the BEGINNING of a loop.

          So if you have the following story: (COMPLETELY useless, but trying to illuminate how 'continue' is used)

          while iterations < 10
            m118 s{"This is iteration " ^ iterations}
            if iterations > 5
              continue  ; Don't do this stuff after the first 5 iterations
            m118 s{"Perform this action on " ^ iterations}
          
          This is iteration 0
          Perform this action on 0
          This is iteration 1
          Perform this action on 1
          This is iteration 2
          Perform this action on 2
          This is iteration 3
          Perform this action on 3
          This is iteration 4
          Perform this action on 4
          This is iteration 5
          Perform this action on 5
          This is iteration 6
          This is iteration 7
          This is iteration 8
          This is iteration 9
          

          SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

          1 Reply Last reply Reply Quote 0
          • alankilianundefined
            alankilian @jens55
            last edited by

            @jens55 said in Meta commands:

            Here is another thing that strikes me as odd:

            while true
              if iterations < 10
                m118 s"hello world"
                g4 s2
                continue
              if iterations < 11
                m118 s"hello north america"
            	g4 s2
            	continue
              break
            

            This code will execute the first 'if' for 10 times but will not reset 'iterations' as I would have expected and because of that will only execute the second 'if' loop once.

            Why do you think 'iterations' will get reset to zero?
            'iterations' counts the number of times through the loop.

            Your 'if' statements will not affect the iteration count at all.

            SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

            1 Reply Last reply Reply Quote 0
            • DanS79undefined
              DanS79 @jens55
              last edited by

              @jens55 said in Meta commands:

              To skip an iteration ???? Where did you see this in the documentation ???
              I look at 'continue' as a command that strictly exists as a means to improve readability of the code since the command itself seems to do diddly squat and can be left out.

              To be clear it doesn't skip an iteration, it skips everything after the continue statement in the current iteration. It goes back to the top of the looping structure and starts the next iteration. Every programming language I can think of works this way.

              1 Reply Last reply Reply Quote 1
              • alankilianundefined
                alankilian @jens55
                last edited by

                @jens55 I'm trying to help you understand how this works, but your responses seem to be accusatory (the interpreter is broken) and inflammatory, so if you don't change your attitude, I'll check out of this conversation.

                I'm really trying to help you understand how to write programs in a clear understandable way.

                Ref: I'm a retired embedded-systems software and hardware engineer who has been programming since about 1978, so I've got the experience to be able to help and in addition, you can help me learn new things also if we both work together on it.

                SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

                jens55undefined 1 Reply Last reply Reply Quote 0
                • jens55undefined
                  jens55 @alankilian
                  last edited by jens55

                  @alankilian, I REALLY appreciate any and all help and I apologize if you felt in any way slighted whatsoever. It was most certainly not my intent !!!
                  I got confused by the sentence "The point of continue is to skip an iteration."
                  DanS79 cleared it up and confirmed my interpretation by saying "To be clear it doesn't skip an iteration, it skips everything after the continue statement in the current iteration." IE it doesn't skip an iteration but goes back to the beginning of the loop.
                  Your example (thanks) did however clarify another point on the continue command that I was not aware of and hence my earlier confusion about sequential 'if' statements. The iteration happens over the 'while' loop and not as I had assumed over the 'if' loop. A very important bit of learning for me!
                  So to repeat, I apologize profusely and hope we are back on the same wavelength !

                  alankilianundefined 1 Reply Last reply Reply Quote 3
                  • alankilianundefined
                    alankilian @jens55
                    last edited by

                    @jens55 Awesome!

                    AND, you got me to try some new stuff using meta-commands, so everyone wins.

                    SeemeCNC Rostock Max V3 converted to V3.2 with a Duet2 Ethernet Firmware 3.2 and SE300

                    1 Reply Last reply Reply Quote 0
                    • OwenDundefined
                      OwenD
                      last edited by

                      @jens55
                      Poor choice of words on my part. , but the code should have been clear enough
                      Apologies for confusing you.
                      I'm Australian, so English isn't my first language 😂

                      jens55undefined 1 Reply Last reply Reply Quote 0
                      • jens55undefined
                        jens55 @OwenD
                        last edited by

                        @owend, no problem and thanks for chiming in !

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Unless otherwise noted, all forum content is licensed under CC-BY-SA