How to loop and increment a value in a dos batch file

the code below is basically a for loop that continues until a counter reaches a value..

@echo off
:: turn off echo
set /a var=1
:: initialize a numeric variable and set it to 1
:LOOP
:: a label to define the start of the loop
if %var% gtr 254 goto :END
:: the if test the variable and if it is > 254 (gtr) it sends the code to the label END
echo %var%
::return current value to screen
set /a var+=1
::increment counter
goto LOOP
::go back to the top of the loop and increment the number again.
:END

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>