控制循环量(批处理文件)

时间:2013-07-22 00:32:48

标签: batch-file

我想知道是否有办法对批处理文件的循环设置限制。 我的意思是:说我有一个剧本:

@echo off
:start
echo Enter the password
set /p password=
if %password%== abcdefg goto correct
if not %password%== abcdefg goto start
:correct
echo good job
timeout 2 > nul
exit
:wrong
echo You are wrong
timeout 1 > nul
exit

说我想要你开始三次,然后你就错了。我该怎么做?

1 个答案:

答案 0 :(得分:0)

@echo off
setlocal enabledelayedexpansion
for /L %%a in (1, 1, 3) do (
set /p "password=Enter the password: "
if "!password!"=="abcdefg" goto :correct
echo You are wrong, try again
timeout /t 1 >nul
)
exit
:correct
echo good job
timeout /t 2 > nul
exit