title: How to increment variable under DOS?
body: <p>I've spent the past 3hrs trying to work this out but just couldn't find a solution. Here's my batch script:</p>
  
  <pre><code>if NOT Exist Counter.txt GOTO START
  Type c:\counter.txt
  if %COUNTER% EQU %Cycles% goto Pass
  if NOT %COUNTER% EQU %Cycles% goto Cycle
  
  :START
  Set COUNTER=0
  set CYCLES=250
  
  :Cycle
  set /A COUNTER=%COUNTER%+1     &lt;----------- PROBLEM
  echo Iteration %COUNTER% of %CYCLES%
  echo Delay 3 seconds to reboot
  choice /cy /n /t:y,3
  warmboot.com
  
  :Pass
  pause
  </code></pre>
  
  <p>What it's doing is it runs the file "warmboot.com" (which reboots my PC) and runs for 250 cycles. Once the cycles have run 250 times (i.e when counter equals cycles) then it stops.</p>
  
  <p>Under Windows, this works. However, this doesn't work under DOS environment. I've tried versions from v4 all the way up to v6.22 and even v7 and they all fail when it reaches the "PROBLEM" line.</p>
  
  <p>If I do this:</p>
  
  <pre><code>set /A COUNTER=%COUNTER%+1
  echo %Counter%
  </code></pre>
  
  <p>OR this:</p>
  
  <pre><code>set /A COUNTER+=1
  echo %Counter%
  </code></pre>
  
  <p>both will return a blank line, i.e it shows nothing as the output. </p>
  
  <p>If I type:</p>
  
  <pre><code>set /?
  </code></pre>
  
  <p>then it shows this:</p>
  
  <blockquote>
    <p>Displays, sets, or removes cmd.exe environment variables.</p>
    
    <p>SET [variable=[string]]</p>
    
    <p>variable  Specifies the environment-variable name.<br>
      string   Specifies a series of characters to assign to the variable.</p>
  </blockquote>
  
  <p>but typing the same command under CMD in Windows shows a lot more stuff. I'm thinking that the SET function under DOS doesn't support arithmetic functions, but for work purposes I have to run my scripts in DOS only.</p>
  
  <p>Any ideas?</p>