Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to write a batch file that repeats the same command (that takes a parameter) for each of three variable values already defined in the batch file. I want to loop over the variable values.

I'm pretty open minded to what the syntax looks like, as long as I don't have to duplicate/repeat in the code the command that needs to happen for each value.

share|improve this question
up vote 3 down vote accepted

You're looking for the FOR command:
http://www.robvanderwoude.com/for.php

FOR %A IN (list) DO command [ parameters ]

For example, this command will run on your computer and print out 1,2,3:

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .