For Loop counting from 1 to n in a windows bat script

Posted by raoulsson on Server Fault See other posts from Server Fault or by raoulsson
Published on 2009-08-26T14:09:36Z Indexed on 2012/09/10 15:40 UTC
Read the original article Hit count: 271

Filed under:
|
|

I need to run a windows command n times within a bat script file. I know how to do this in various programming languages but cannot manage to get it right on the windows command line :-(

I would expect something like either

for(int i = 0; i < 100; i++) {
   // do something
}

or even this (though not entirely seriously)

1.upto(100, {
   // do something
})

Thanks!

EDIT

I can write a program in java, perl, c or whatever that will generate a bat script that looks like this

for %%N in (1 2 3 4 5 6 7 8 9 10 11 12) do echo %%N

and so on. Or even "better":

echo 1
echo 2
echo 3
echo 4
echo 5
echo 6
echo 7
echo 8
echo 9
echo 10
echo 11
echo 12

and then execute it... But the thing is that I need a concise way to specify a range of numbers to iterate through within the script.

Thanks!

© Server Fault or respective owner

Related posts about Windows

Related posts about batch