Batch: goto was unexpected at this time error -


so im making project school , want goto menu if user input not valid
code this:

:menu   echo.   echo.   echo know first? echo. echo. echo 1) salary echo 2) do? echo 3) schools near me offer game design programs echo 4) requirements echo 5) credits echo. echo. set /p choice="enter number: " if %choice% == 1 goto salary if %choice% == 2 goto if %choice% == 3 goto schools if %choice% == 4 goto req if %choice% == 5 goto credits goto menu 

when enter input, there line flashes
goto unexpected @ time exits
doing wrong?
should add input not valid option. (1,2,3,4,5)

if %choice% == 1 goto salary 

imagine, do, when %choice% empty. line read as:

if  == 1 goto salary 

obviously syntax error. "goto unexpected".

to avoid this, use

if "%choice%" == "1" goto salary 

this read as:

if "" == "1" goto salary 

syntax ok now.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -