Windows批处理标签循环

时间:2016-11-11 05:03:10

标签: loops batch-file if-statement

很难运行我的批处理文件 我认为它与我的if语句有关,它不会落空。
我总是最终得到“如果此时出乎意料的话” 请任何帮助表示感谢

:firstNumber
set /p "firstNum = Enter the first number (other than 22) "
if "%firstNum%"=="22" (
goto :end
) else (
goto :secondNumber
)

:secondNumber
set /p "secondNum = Enter the second number (other than 22 and 0) "
if "%secondNum%"=="22" (
goto :end
)   if "%secondNum%"=="0" (
goto :errorNumber
) else (
goto :command
)

:errorNumber
echo You cannot divide by 0
goto :secondNumber

:command
set /a quotient=%firstNum% / %secondNum% 
echo "%firstNum% divided by %secondNum% = !quotient!

:end

1 个答案:

答案 0 :(得分:0)

)   if "%secondNum%"=="0" (

应该是

)
if "%secondNum%"=="0" (

)终止上一个if语句。 cmd将该行的其余部分视为不应遵循)

的内容

(稍后 - 缺少操作数...)

批处理对SET语句中的空格敏感。 SET FLAG = N将名为“FLAG Space ”的变量设置为值“ Space N”

因此,您的set /p "firstnum = ...设置了一个名为“firstNum Space ”的变量 - 这与变量“firstNum”

不同

由于firstnumsecondnum都不包含值,cmd会看到

  

设置/商= /

丢失=语句中set两侧的空格。