O'Reilly logo

Windows XP in a Nutshell by Troy Mott, Tim O'Reilly, David A. Karp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

for

Synopsis

Repeat a specified command any number of times.

Syntax

for [/d] %%variable in (set) do command [arguments]
for /r [path] %%variable in (set) do command [arguments]
for /r [path] %%variable in (set) do command [arguments]
for /l %%variable in (start,step,end) do command [arguments]

(in and do are not options, but rather simply part of the syntax; if omitted, an error will occur.)

Description

Use this command to create loops in a batch file. A for loop is a programming construct that allows you to repeat a command for a list of items (such as filenames). You specify an arbitrary variable name and a set of values to be iterated through. For each value in the set, the command is repeated.

The options used by for are the following:

command [ arguments ]

The command to execute or the program filename to run. This can be anything you’d normally type at a command prompt; arguments are the options, if any, to pass to the command.

%% variable

A one-letter variable name that is assigned, one by one, to the elements listed in set. Although variable is treated like a standard environment variable (see set, earlier in this chapter), it’s name is case sensitive (%%j is different than %%J) and can only be one letter long. Note also the use of two preceding percent signs. If the for command is issued directly from the command prompt (and not from within a batch file), use only one percent sign here.

set

The sequence of elements through which the for command cycles. Elements are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required