Ok, just off the top of my head here is a simple one. Set a variable and run a piece of code that many times.
#500 = 5
O20
routine 1 here
#500 = #500-1
M500
M98 P#502
O30
G code routine 2
M500.m1s file goes in macros/your profile and contains
Sub main ()
a = GetVar (500)
If a > 0 Then GoTo set20
SetVar(502,30)
GoTo set30
set20:
SetVar(502,20)
set30:
End
End Sub