Link to home
Start Free TrialLog in
Avatar of mikeydk
mikeydkFlag for Denmark

asked on

Count 00, 01, 02... in vbscript

Hey

Is there a more elegant way to count ... 00, 01, 02, 03... in vbscript


i = 0
do while i <= 20

if i < 10 then
wscript.echo "0" & i
else
wscript.echo i
end if

i = i + 1
loop
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

@Martin,

Yes, from a pure performance point of view, that would be "faster".  But it really depends on the usage.  If it really is just to generate the numbers then I might lead toward the single loop approach, since there's likely some logic inside the loop to execute, and I wouldn't want to repeat that twice.  But we'd need more info on the use case.

For what it's worth, for the 1...20 loop, I did a test of each approach, and they were both instance, taking essentially no time.  I had to do a loop of 10000 iterations around each approach to see some differences, and yes, the Right() approach took maybe .2 secs to run, compared to .1 for your dual loop approach.  Definitely faster, and if we had to do this a million times we'd clearly want the dual loop approach.

Thanks for the thoughts, good dialog!

~bp
You might be interested in my article of timing code.
Thanks, glad that was helpful.

~bp