How to do looping in Windows Batch

Source from Tine Ivanič

We need loops in batch file to prevent writing long blocks of code and to do repetitive process. There are 2 ways to do looping in Windows Batch.

Method 1

Use this method for numeric values

FOR /L %%A IN (1,1,200) DO (
ECHO %%A
)
where 1,1,200 means start, increment step and end

Method 2

Use this method for non-numeric values

FOR %%G IN (Sun Mon Tue Wed Thur Fri Sat) DO echo %%G

Leave a comment

Design a site like this with WordPress.com
Get started