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

About the author

Founder of tattweicheah.com. Loves music, sport and most importantly software development.

Leave a Reply

Your email address will not be published. Required fields are marked *