Page 1 of 1

Times

Posted: Thu Dec 05, 2013 6:14 pm
by netmaestro
From the help file:

Code: Select all

 
a=0
Repeat 
  a=a+1
Until a>100
; This will loop until "a" takes a value > to 100, (it will loop 101 times). 
Rather than define and increment a counter if I want to execute something a specific number of times this would be handy:

Code: Select all

Repeat
   ; some lines of code
5 Times
Not exactly a game-changer but when you're doing a lot of quick tests it would save some time. More streamlined than For-Next and nicely self-documenting.

Re: Times

Posted: Thu Dec 05, 2013 8:39 pm
by luis
I can think to an overwhelming number of possible scenarios suggesting the need of a loop indexed in some way, but I have an hard time to find more than some where you want just to loop blindly without a counter of some sort instead.
And after all the generated code still will have the counter, so... meh :)

Re: Times

Posted: Thu Dec 05, 2013 9:16 pm
by ostapas
+1, looks simple and laconic and there may be not so few situations where you don't need loop index.

Re: Times

Posted: Thu Dec 05, 2013 9:26 pm
by Little John
Here is a self-made solution. :-)

Code: Select all

EnableExplicit

Macro DoTimes (_times_)
   CompilerIf Not Defined(DoTimesRepeatCount, #PB_Variable)
      Define DoTimesRepeatCount.i
   CompilerEndIf
   For DoTimesRepeatCount = 1 To _times_
EndMacro


DoTimes(3)
   Debug "Hi"
Next

DoTimes(3)
   Debug "there!"
Next

Re: Times

Posted: Thu Dec 05, 2013 10:16 pm
by STARGÅTE
for recursive support:

Code: Select all

Macro DoTimes (_times_)
   Define DoTimesRepeatCount#MacroExpandedCount.i
   For DoTimesRepeatCount#MacroExpandedCount = 1 To _times_
EndMacro


DoTimes(3)
	DoTimes(3)
	   Debug "there!"
	Next
Next

Re: Times

Posted: Fri Dec 06, 2013 12:23 am
by PB
> Repeat
> ; some lines of code
> 5 Times

A quick macro which is close to your specific syntax request:

Code: Select all

Global timescount

Macro Times(num)
  timescount+1
  Until timescount=num
  timescount=0
EndMacro

Repeat
  Debug "Pure"
Times(5)

Repeat
  Debug "Basic"
Times(5)
But syntax coloring doesn't match, and it doesn't support nesting. TIOLI. :lol:

Re: Times

Posted: Fri Dec 06, 2013 12:36 am
by davido
Thanks Guys. Some nice ideas.

Hi PB,

Sorry I can't help with the nesting.

But you can get the colour correct by making Times a custom variable and making the custom variable the same colour as system variables.

Re: Times

Posted: Fri Dec 06, 2013 5:59 am
by Little John
Cool, STARGÅTE. 8)