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

Solution 1:

You can do it similarly like this:

ECHO Start of Loop

FOR /L %i IN (1,1,5) DO (
  ECHO %i
)

The 1,1,5 is decoded as:

(start,step,end)

Also note, if you are embedding this in a batch file, you will need to use the double percent sign (%%) to prefix your variables, otherwise the command interpreter will try to evaluate the variable %i prior to running the loop.

Solution 2:

Directly from the command line:

for /L %n in (1,1,100) do @echo %n

Using a batch file:

@echo off
for /L %%n in (1,1,100) do echo %%n

Displays:

1
2
3
...
100

Solution 3:

Syntax is

FOR %%A IN (1 2 3) DO ECHO %%A

Good article here and XP specifics here