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

    How to write a gcode loop for exactly N iterations?

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    5
    331
    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.
    • zaptaundefined
      zapta
      last edited by zapta

      I have a test macro file with an infinite loop which want to change to exactly 100 iterations. What is the gcode idiom for iterating N times where N is a constant?

      while true
        g1 x0 y0 f30000
        g1 x240 y0 f30000
        g1 x240 y240 f30000
        g1 x0 y240 f30000
      
      jay_s_ukundefined dc42undefined 2 Replies Last reply Reply Quote 0
      • jay_s_ukundefined
        jay_s_uk @zapta
        last edited by jay_s_uk

        @zapta this should work

        while true
          If iterations > 100
            Abort
          g1 x0 y0 f30000
          g1 x240 y0 f30000
          g1 x240 y240 f30000
          g1 x0 y240 f30000
        

        Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

        1 Reply Last reply Reply Quote 0
        • dc42undefined
          dc42 administrators @zapta
          last edited by

          @zapta use:

          while iterations <100

          Duet WiFi hardware designer and firmware engineer
          Please do not ask me for Duet support via PM or email, use the forum
          http://www.escher3d.com, https://miscsolutions.wordpress.com

          zaptaundefined 1 Reply Last reply Reply Quote 0
          • zaptaundefined
            zapta @dc42
            last edited by

            Thanks @jay_s_uk and @dc42. This is exactly what I was looking for.

            BTW, since 'iterations' is loop specific, may be helpful to mention it also in the loop section.

            https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Loop

            dc42undefined 1 Reply Last reply Reply Quote 0
            • dc42undefined
              dc42 administrators @zapta
              last edited by

              @zapta said in How to write a gcode loop for exactly N iterations?:

              BTW, since 'iterations' is loop specific, may be helpful to mention it also in the loop section.

              Done!

              Duet WiFi hardware designer and firmware engineer
              Please do not ask me for Duet support via PM or email, use the forum
              http://www.escher3d.com, https://miscsolutions.wordpress.com

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