Home > Commands A-M > Batch F

FOR /L


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Conditionally perform a command for a range of numbers.


Syntax

FOR /L /?

To use FOR in a batch program:

FOR /L %%variable IN (start,step,end) DO command [command-parameters]

To use FOR from the command prompt:

FOR /L %variable IN (start,step,end) DO command [command-parameters]


Parameters
command (NT4)
The command to carry out, including any command-line parameters.
command-parameters (NT4)
Specifies any parameters or switches that you want to use with the specified command (if the specified command uses any parameters or switches).
end) (NT4)
The last number.
(start, (NT4)
The first number.
,step, (NT4)
The amount by which to increment the sequence.
%variable or %%variable (NT4)
Represents a replaceable variable. The FOR command replaces %%variable (or %variable) with each text string in the specified set until the command (specified in the command parameter) processes all the folders. Use %%variable to carry out the FOR command within a batch program. Use %variable to carry out FOR from the command prompt. (Do NOT use %0 through %9 to avoid confusion with the command-line arguments passed to the batch file).

Switches
/? (NTXP)
Display help.

Related

FOR - Loop through a set of files in one folder.
FOR /R - Loop through files (recurse subfolders).
FOR /D - Loop through several folders.
FOR /F - Loop through items in a text file.
FOR /F - Loop through the output of a command.
FORFILES - Batch process multiple files.
GOTO - Direct a batch program to jump to a labelled line.
IF - Conditionally perform a command.
Equivalent Linux BASH commands:
for - Expand words, and execute commands.
case - Conditionally perform a command.
eval - Evaluate several COMMANDS/arguments.
if - Conditionally perform a command.
gawk - Find and Replace text within file(s).
m4 - Macro processor.
until - Execute commands (until error).
while - Execute commands.


Notes

none.


Examples
    FOR /L %%G IN (20,-5,10) DO ECHO %G

20
15
10
    FOR /L %%G IN (1,1,5) DO ECHO %G

1
2
3
4
5

Errorlevels

none.


Availability
Internal
DOS
none
Windows
none
Windows NT
NT4 NT2000 NTXP NT2003