title: Flow control in a batch file
body: <p>Reference <a href="https://stackoverflow.com/questions/2725511/iterating-arrays-in-a-batch-file">Iterating arrays in a batch file</a></p>
  <p>I have the following:</p>
  <pre><code>for /f &quot;tokens=1&quot; %%Q in ('query termserver') do (
      if not ERRORLEVEL (
          echo Checking %%Q
          for /f &quot;tokens=1&quot; %%U in ('query user %UserID% /server:%%Q') do (echo %%Q)
      )
  )
  </code></pre>
  <p>When running <code>query termserver</code> from the command line, the first two lines are:</p>
  <pre><code>Known
  ------------------------- 
  </code></pre>
  <p>...followed by the list of terminal servers. However, I do not want to include these as part of the <code>query user</code> command. Also, there are about 4 servers I do not wish to include. When I supply <code>UserID</code> with this code, the program is promptly exiting. I know it has something to do with the <code>if</code> statement. Is this not possible to nest flow control inside the for-loop?</p>
  <p>I had tried setting a variable to exactly the names of the servers I wanted to check, but the iteration would end on the first server:</p>
  <pre><code>set TermServers=Server1.Server2.Server3.Server7.Server8.Server10
  
  for /f &quot;tokens=2 delims=.=&quot; %%Q in ('set TermServers') do (
      echo Checking %%Q
      for /f &quot;tokens=1&quot; %%U in ('query user %UserID% /server:%%Q') do (echo %%Q)
  )
  </code></pre>
  <p>I would prefer this second example over the first if nothing else for cleanliness.</p>
  <p>Any help regarding either of these issues would be greatly appreciated.</p>