title: Batch Script to edit input file for a program
body: <p>I'm trying to write a script that will edit an input file with varying parameters and run a program that uses that input file. I would like to do 200+ runs. I've written code that does one run successfully, but does not work when I try to put the same code in a FOR loop.</p>
  
  <p>This is the code for one iteration that works fine</p>
  
  <pre><code>@echo
  set "file=Current.hot"
  set /a isoLine#ToSearch=67
  set /a sourceLine#ToSearch=68
  
  set sourceList[0]=SourceTerm = 300
  set isoList[0]=SourceTermName = a
  set fileList[0]=a
  
  set sourceList[1]=SourceTerm = 30
  set isoList[1]=SourceTermName = ab
  set fileList[1]=ab
  
  set sourceList[2]=SourceTerm = 3
  set isoList[2]=SourceTermName = ac
  set fileList[2]=ac
  
  set sourceList[3]=SourceTerm = .3
  set isoList[3]=SourceTermName = ad
  set fileList[3]=ad
  
  
  (FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
      SETLOCAL ENABLEDELAYEDEXPANSION
      SET "Line=%%b"
      IF %%a equ %isoLine#ToSearch% SET "Line=!isoList[3]!"
      IF %%a equ %sourceLine#ToSearch% SET "Line=!sourceList[3]!"
      ECHO !Line!
      ENDLOCAL
  ))&gt;"%file%.new"
  TYPE "%file%.new"
  MOVE "%file%.new" "%file%"
  
  
  setlocal enabledelayedexpansion
  cd C:\Program Files (x86)\HotSpot 3.0.3
  start Hotspot303.exe
  timeout /t 4
  ren Current.out !fileList[3]!.txt
  </code></pre>
  
  <p>Now here is the same code with my attempt to make it into a loop.</p>
  
  <pre><code>@echo off 
  
  set "file=Current.hot"
  set /a isoLine#ToSearch=67
  set /a sourceLine#ToSearch=68
  
  set sourceList[0]=SourceTerm = 300
  set isoList[0]=SourceTermName = a
  set fileList[0]=a
  
  set sourceList[1]=SourceTerm = 30
  set isoList[1]=SourceTermName = ab
  set fileList[1]=ab
  
  set sourceList[2]=SourceTerm = 3
  set isoList[2]=SourceTermName = ac
  set fileList[2]=ac
  
  set sourceList[3]=SourceTerm = .3
  set isoList[3]=SourceTermName = ad
  set fileList[3]=ad
  
  (for /l %%k in (0,1,3 ) do (    
      (FOR /f "tokens=1*delims=:" %%a IN ('findstr /n "^" "%file%"') DO (
          SETLOCAL ENABLEDELAYEDEXPANSION
          SET "Line=%%b"
          IF %%a equ %isoLine#ToSearch% SET "Line=!isoList[%%k]!"
          IF %%a equ %sourceLine#ToSearch% SET "Line=!sourceList[%%k]!"
          ECHO !Line!
          ENDLOCAL
      ))&gt;"%file%.new"
      TYPE "%file%.new"
      MOVE "%file%.new" "%file%"
  
  
      setlocal enabledelayedexpansion
      cd C:\Program Files (x86)\HotSpot 3.0.3
      start Hotspot303.exe
      timeout /t 4
      ren Current.out !fileList[%%k]!.txt
  ))
  </code></pre>
  
  <p>Any thoughts on why this stops working when placed in a loop?</p>
  
  <p>Thanks</p>