Got an idea for enhancing PureBasic? New command(s) you'd like to see?
netmaestro
PureBasic Bullfrog
Posts: 8452 Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada
Post
by netmaestro » Thu Dec 05, 2013 6:14 pm
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.
BERESHEIT
luis
Addict
Posts: 3895 Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy
Post
by luis » Thu Dec 05, 2013 8:39 pm
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
"Have you tried turning it off and on again ?"
ostapas
Enthusiast
Posts: 192 Joined: Thu Feb 18, 2010 11:10 pm
Post
by ostapas » Thu Dec 05, 2013 9:16 pm
+1, looks simple and laconic and there may be not so few situations where you don't need loop index.
Little John
Addict
Posts: 4801 Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany
Post
by Little John » Thu Dec 05, 2013 9:26 pm
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
STARGÅTE
Addict
Posts: 2258 Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:
Post
by STARGÅTE » Thu Dec 05, 2013 10:16 pm
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
PB
PureBasic Expert
Posts: 7581 Joined: Fri Apr 25, 2003 5:24 pm
Post
by PB » Fri Dec 06, 2013 12:23 am
> 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
davido
Addict
Posts: 1890 Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK
Post
by davido » Fri Dec 06, 2013 12:36 am
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.
DE AA EB
Little John
Addict
Posts: 4801 Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany
Post
by Little John » Fri Dec 06, 2013 5:59 am
Cool, STARGÅTE.