subroutines in DOS batch files

@echo off
echo Subroutines in DOS batch files proof-of-concept 0.02
echo by Daren Freckleton August 25, 2000
echo tweaked by tehdr33mah, who just _loves_ that GOTO ENVAR

rem -----------------------------------------------------------------

rem This algorithm can repeatedly call a generic subroutine embedded
rem within the same DOS batch file.  This could be useful if, for
rem example, you have a list of items for processing by the same set
rem of DOS batch commands.

rem It works by setting a control variable, in addition to any
rem variables required by the subroutine.  This variable is a pointer
rem to the routine that called the subroutine - in fact it is the 
rem name of a ':label' embedded in the calling subroutine.  The
rem calling routine, which has the embedded label, sets the control
rem variable RETURN to its label, sets any variables for the subroutine
rem to process, and then calls the subroutine.  The subroutine executes
rem as usual, but on ending executes a GOTO %RETURN%.  This causes
rem execution to jump to the label embedded in the calling routine.
rem Execution can then continue from where the call was made.

rem The algorithm thus consists of two parts, a section of the calling
rem routine, and the final GOTO in the subroutine.

rem ------------------------------------------------------------------

set RETURN=item-a
goto subroutine

set RETURN=item-b
goto subroutine

set RETURN=item-c
goto subroutine

goto end

echo pinging %IPADDRESS% ...
ping -n 1 %IPADDRESS% | find /i "packets:"
goto %RETURN%

this site only