- @if not defined DEBUG (@echo off)
- title 倒计时练习批处理&chcp 936>nul&color 0A
-
- :Menu
- set "choice="
- echo.&echo.
- echo. 倒计时练习批处理
- echo. 1.利用for /L 计时
- echo. 2.利用if和goto计时
- echo. 3.利用call和shift计时
- echo. 4.退出
- echo.
- set /p "choice= 请选择:"
- if "%choice%" equ "1" color 1A&goto 01_For
- if "%choice%" equ "2" color 2A&goto 02_if
- if "%choice%" equ "3" color 3A&goto 03_shift
- if "%choice%" equ "4" goto Exit
- echo 非法输入!
- ping -w 2 -n 2 127.0.0.1>nul 2>&1
- cls
- goto Menu
-
- :: 1.利用for /L 计时
- :01_For
- echo.1.利用for /L 计时
- for /l %%i in (10,-1,1) do (
- set /p=%%i <nul
- ping -w 2 -n 2 127.0.0.1>nul 2>&1
- set /p=<nul
- )
- goto End
-
- :: 2.利用if和goto计时
- :02_if
- echo.2.利用if和goto计时
- set "num=11"
- :Loop
- set /a num-=1
- set /p=<nul&set /p=%num% <nul
- ping -w 2 -n 2 127.0.0.1>nul 2>&1
- if "%num%" neq "1" (goto Loop)
- goto End
-
- :: 3.利用call和shift计时
- :03_shift
- echo.3.利用call和shift计时
- set "num=10 9 8 7 6 5 4 3 2 1"
- call :Timer %num%
- goto End
-
- :Timer
- set /p=<nul&set /p=%1 <nul
- ping -w 2 -n 2 127.0.0.1>nul 2>&1
- shift /1
- if "%1" neq "" goto Timer
- goto :eof
-
- :End
- echo.&echo 倒计时结束,按任意键继续...
- pause>nul&cls&goto Menu
-
- :Exit
- exit
复制代码
|