Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Tue 20-Apr-2010 07:42:14

Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.

103} How do I exit a loop by pressing a key?

You may wish to revisit item #14 first. Anyway:
  @echo off & setlocal enableextensions
  :: Test for CHOOSE.EXE availability at path / in the current folder

  for %%f in ("CHOOSE.EXE") do set found_=%%~$PATH:f
  if exist CHOOSE.EXE set found_=CHOOSE.EXE
  if "%found_%"=="" (
    echo CHOOSE.EXE choice.com clone not found.
    echo Available from tscmd.zip
    goto :EOF)
  echo Press x to exit the loop
  set /a i_+=1
  choose /n /c:nx /tn,0 > nul
  if %errorlevel% NEQ 2 goto _loop
  echo i_=%i_% ^(cycles^)
  endlocal & goto :EOF

The output would be e.g.
  Press x to exit the loop
  i_=37 (cycles)