Printer Version Table of Contents Project Home Page
.EXAMPLE.....: 43 Loop through an array of environment variables
.CATEGORY....: examples
.DISCUSSION..:
.CODE........:
@echo off
cls
SET pct=%%%
SET prefix=Address

echo LOADING AN ARRAY
SET subscript=1
SET %prefix%.%subscript%=Stephen Ferg
SET subscript=2
SET %prefix%.%subscript%=5113 N. 8th Road
SET subscript=3
SET %prefix%.%subscript%=Arlington, VA 22205

echo UNLOADING AND DISPLAYING THE ARRAY
SET subscript=1

:LoopTop
:: do while subscript less than/equal 3
if %subscript%==4 goto LoopEnd

   REM put value of subscripted variable into tempvar
   ECHO SET tempvar=%pct%%prefix%.%subscript%%pct%>JUNKTEMP.BAT
   CALL JUNKTEMP.BAT

   REM display value of subscripted variable
   ECHO %prefix%.%subscript% is: %tempvar%

   REM delete subscripted variable
   SET %prefix%.%subscript%=

   REM increment the loop variable
   Fdate /F#add /A%subscript% /B1 /Vsubscript
   goto LoopTop

:LoopEnd

SET pct=
SET tempvar=
SET prefix=
SET subscript=
DEL JUNKTEMP.BAT