Answer the question
In order to leave comments, you need to log in
Why does the condition not work and does not display the result?
@echo off
set /p option =
if '%option%' == '1' (goto ":math")
if '%option%' == '2' (start "test.txt")
:math
echo 2+2
pause
Answer the question
In order to leave comments, you need to log in
1.Arithmetic operations are only supported in the command set /a
(see set /?
)
2.The quotes in the condition must be double.
3. Post the output option ( ) after set /p to make sure that the variable contains the value that you entered from the keyboard.
4. Labels in goto are specified without quotes
5. As far as I can tell, you need to do exit /b between the second if and the label. Now the code in the label will work for you anyway, even if you enter 2 (in this case, the test.txt file will open and 2 + 2 will be displayed).
PS: now I don't have Windows at hand, I can't test your codeecho %option%
@echo off
set /p "option="
if "%option%" == "1" (goto:math)
if "%option%" == "2" (start "test.txt")
exit /b
:math
set /a "val=2+2"
echo %val%
pause
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question