if statement - Go Back to Start If no input is entered (Bat File) -
ok first have i'm sorry poor english :) problem
i'm trying create script file multiple choices , ran problem. if don't enter input (just press enter) file displays error , shuts down. question whether there command force file go start in case no input entered?
this relevant part of script
:input @echo off cls echo ############################################# echo # # echo # 1 - make system folder or file # echo # 2 - restore folder or file # echo # 3 - exit # echo # # echo ############################################# set /p o=set choice , press enter: echo loading ......... ( if %o%==1 goto hide if %o%==2 goto show if %o%==3 goto exit if %o%=="" goto input ) else ( goto input )
as can see tried use "else" works partially. if enter variable not part of list given (in case 1, 2, 3) file gose beginning, , if send non input request afterword file keep working properly. problem specific, when first input non input problem occurs. in other situation script works fine
thank , again i'm sorry poor english :)
always reset variable before input. when user presses enter variable doesn't reset automatically.
:: delete variable %o% set "o=" set /p "o=set choice , press enter: "
always take variables in quotes (in if)
if "%o%"=="1" goto hide if "%o%"=="2" goto show if "%o%"=="3" goto exit
goto label
never returns (exception -goto :label
in crazy cases). in case can write:if "%o%"=="1" goto hide if "%o%"=="2" goto show if "%o%"=="3" goto exit goto input
add after each 'procedure' command
exit /b
prevent crazy parsing after code changing. warning:goto
command doesn't workvoid
in c++, commandexit /b
stop script. if usingcall :label
commandexit /b
stop code under:label
.
Comments
Post a Comment