@echo off
rem a quick working example of loops in DOS BATCH files, by Daren Freckleton
rem
rem essential components:
rem 1. SET statement with name of list of variables on the left;
rem 2. SET statement with comma-separated list of variables on the right;
rem 3. FOR statement with name of list substituting for variable list;
rem 4. FOR statement with action to take on the right.
set var_list=1,2,3,4
for %%i in (%var_list%) do echo %%i
Note: the MS-DOS documentation appears hazy about this point: the %%i variable must be one character in length ONLY. Incorrect: