title: dos batch iterate through a delimited string
body: <p>I have a delimited list of IPs I'd like to process individually.  The list length is unknown ahead of time.  How do I split and process each item in the list?</p>
  
  <pre><code>@echo off
  set servers=127.0.0.1,192.168.0.1,10.100.0.1
  
  FOR /f "tokens=* delims=," %%a IN ("%servers%") DO call :sub %%a
  
  :sub
      echo In subroutine
      echo %1
  exit /b
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>In subroutine
  127.0.0.1
  In subroutine
  ECHO is off.
  </code></pre>
  
  <p><strong>Update:</strong>
  Using Franci's answer as reference, here's the solution:</p>
  
  <pre><code>@echo off
  set servers=127.0.0.1,192.168.0.1,10.100.0.1
  
  call :parse "%servers%"
  goto :end
  
  
  :parse
  setlocal
  set list=%1
  set list=%list:"=%
  FOR /f "tokens=1* delims=," %%a IN ("%list%") DO (
    if not "%%a" == "" call :sub %%a
    if not "%%b" == "" call :parse "%%b"
  )
  endlocal
  exit /b
  
  :sub
  setlocal
  echo In subroutine
  echo %1
  endlocal
  exit /b
  
  :end
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>In subroutine
  127.0.0.1
  In subroutine
  192.168.0.1
  In subroutine
  10.100.0.1
  </code></pre>