This tutorial shows multiple ways to increment a variable in DOS batch programming.

How to increment a variable windows dos-batch programming?

There are multiple ways we can increment the variable or counter in batch programming.

  • use for loop

for loop is used to run with n number of iterations. for with /L option used to iterate with start=1, stop=1 and end=10 values in expression The number started with 1 and incremented by 1 until the counter is reached 20

 @echo off
 for /L %%n in (1,1,20) do echo %%n



Another way without for loop

Initializes variable with value 1 Print the value and increment the variable using set /a Print the counter up to 20 times. a

set counter=1
echo %counter%
set /a counter=counter+1
if %counter% EQU 20 goto end
goto begin