If you are using LinuxCNC, then the code below would be the code used to loop or iterate some lines of gcode.
FYI, LinuxCNC and gcode can be more difficult to own than most of the other common programming languages … python, R, etc...
And LinuxCNC does not accept just any old gcode. The AXIS in my LinuxCNC rejected the code in the other answer that is shown below. LinuxCNC wants the formatting to be exact - including brackets, starting / ending file characters, etc....
This code works in the AXIS GUI in LinuxCNC.
%
/ Tool is set at starting position. Enter the conditional loop
#100 = 1
o101 while [#100 le 5]
G1 X -0.02 F10
G54 Z -.25 F10
G0 X0.0
G54 Z0.0
#100 = [#100 + 1]
o101 endwhile
M2
%