tags:

views:

336

answers:

3

I want the syntax for FOR loop in batch file,windows

+2  A: 

Type:

for /?

and you will get several pages of help text.

Greg Hewgill
+2  A: 
FOR %A IN (list) DO command [ parameters ]

list is a list of any elements, separated by either spaces, comma's or semicolons.

command can be any internal or external command, batch file or even - in OS/2 and NT - a list of commands

parameters contains the command line parameters for command. In this example, command will be executed once for every element in list, using parameters if specified.

A special type of parameter (or even command) is %A, which will be substituded by each element from list consecutively.

From FOR loops

rahul
Can I give the range (1 TO 100) in list?
Pradeep
`FOR /L %x IN (1,1,100) DO ...`
Joey
A: 

If you want to do somthing x times, you can do this:

Example (x = 200):

FOR /L %%A IN (1,1,200) DO (
  ECHO %%A
)

1,1,200 Means:

  • start = 1
  • increment per step = 1
  • end = 200