# Solved: How to goto a menu after a Loop



## Nerokin (Feb 27, 2013)

I am trying to get a batch file goto another set of code with the IF and ELSE command. I know it could be done another way, but I'd like it to use IF and ELSE for right now. When I run it, I have it paused for a sec ,then it would show the other :start2 and after that have it go to another menu by pressing a button or continue the loop if a button isn't pressed, but, it stops and exits it . Is there a way for it to work with or without IF and ELSE?

Here is the code

```
@echo off

:start1
cls
Echo    Welcome to the
Echo         Menu
Echo      Press Enter
PING 127.0.0.1 -n 2 >nul
IF Enter (goto :Menu
) ELSE (
goto :start2)

:start2
cls
Echo    Welcome to the
Echo         Menu 
PING 127.0.0.1 -n 2 >nul
IF M (goto :Menu
) ELSE (
goto :start1)

:Menu
Echo ______________________
Echo Nothing else to do now
echo ______________________
```


----------



## foxidrive (Oct 20, 2012)

Look at the set /p command and google for examples.

You can also type this for help.
set /?


----------



## Nerokin (Feb 27, 2013)

I know about that command . I made a menu with it and run things from there without trying to look for the file I am looking. but can you give me an example of how it should run?

Here is an example of 'SET /P' command

@echo off
Title Main Screen


```
:Menu
cls
Echo          WELCOME TO THE
Echo               Menu
Echo
Echo Which menu would you like to go to?
Echo 1. Tools
Echo 2. Games
Echo 3. Emulators
Echo 4. Game websites
set /p bat=
IF /I '%BAT%'=='1' goto :num1
IF /I '%BAT%'=='2' goto :num2
IF /I '%BAT%'=='3' goto :num3
IF /I '%BAT%'=='4' goto :num4
goto :noselect

:num1
cls
Echo You are going to the Tools Menu
Echo Press any key to go the Menu
pause>nul
cd Y:\Batch Tools
start ToolsLauncher.bat
goto :end

:num2
cls
Echo You are going to the Games Menu
Echo Press any key to go the Menu
pause>nul
cd Y:\Batch Tools
start GamesLauncher.bat
goto :end

:num3
cls
Echo You are going to the Emulators Menu
Echo Press any key to go the Menu
pause>nul
cd Y:\Batch Tools
start EmulatorLauncher.bat
goto :end

:num4
cls
Echo You are going to the Online Games Menu
Echo Press any key to go the Menu
pause>nul
cd Y:\Batch Tools
start OnlineGamesLauncher.bat
goto :end

:noselect
cls
Echo You didn't select a menu
Echo Press enter to go back
pause>nul
goto :Menu

:end
exit
```


----------



## foxidrive (Oct 20, 2012)

Nerokin said:


> Here is the code
> 
> ```
> IF Enter (goto :Menu
> ...


That is not legal syntax - what are you trying to achieve?


----------



## Nerokin (Feb 27, 2013)

foxidrive said:


> That is not legal syntax - what are you trying to achieve?


I am trying to have it loop while pressing enter to goto a menu


----------



## foxidrive (Oct 20, 2012)

You need to use set /p to use an enter keypress and branch somewhere else in the code.


----------



## Nerokin (Feb 27, 2013)

foxidrive said:


> You need to use set /p to use an enter keypress and branch somewhere else in the code.


This doesn't really help me much. I work better with examples and if you can provide an example that would be great.


----------



## Squashman (Apr 4, 2003)

Nerokin said:


> This doesn't really help me much. I work better with examples and if you can provide an example that would be great.


You already have an example of how to use SET /P. It is in Post #3 of this thread and you posted it.


----------



## Nerokin (Feb 27, 2013)

Oh ok... But how would you use it in a loop, I ment. I have tried that, but it doesn't continue the loop that I have.
Here is the code that has 'set /p' command in it.


```
@echo off
TITLE Main Test Loop

:start1
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter
set /p loop=
IF /I '%LOOP%'=='L' goto :start2
IF /I '%LOOP%'=='M' goto :Menu 
PING 127.0.0.1 -n 2 >nul
goto :start2

:start2
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
set /p loop=
IF /I '%LOOP%'=='L' goto :start1
IF /I '%LOOP%'=='M' goto :Menu 
PING 127.0.0.1 -n 2 >nul
goto :start1

:Menu
cls
Echo ______________________
Echo Nothing else to do now
echo ______________________
pause>nul
```
Or is this what you were talking about?


```
@echo off
TITLE Main Test Loop

:start1
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter 
PING 127.0.0.1 -n 2 >nul
goto :start2

:start2
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu 
PING 127.0.0.1 -n 2 >nul
goto :start3

:start3
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter 
PING 127.0.0.1 -n 2 >nul
goto :start4

:start4
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
PING 127.0.0.1 -n 2 >nul
goto :start5

:start5
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter 
PING 127.0.0.1 -n 2 >nul
goto :start6

:start6
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu 
PING 127.0.0.1 -n 2 >nul
goto :start7

:start7
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter 
PING 127.0.0.1 -n 2 >nul
goto :start8

:start8
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu 
PING 127.0.0.1 -n 2 >nul
goto :start9

:start9
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter 
PING 127.0.0.1 -n 2 >nul
goto :start10

:start10
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
PING 127.0.0.1 -n 2 >nul
goto :start11

:start11
cls
Echo           Welcome to the
Echo    __   __       __   ____  __
Echo   //\\ //\\     //\\   ()  ((\\  ((
Echo  //   Y   \\   //__\\  ()   ))\\  ))
Echo ((    I    )) ((    )) ()  ((  \\((
Echo  ))   I   ((   ))  (( _()_  ))  \\))
Echo                 Menu
Echo              Press Enter 
Echo     Do you want to stop the Loop?
Echo              Yes or No
set /p loop=
IF /I '%LOOP%'=='Y' goto :Menu
IF /I '%LOOP%'=='YES' goto :Menu
IF /I '%LOOP%'=='N' goto :start1
IF /I '%LOOP%'=='NO' goto :start1
PING 127.0.0.1 -n 2 >nul
goto :start2

:Menu
cls
Echo ______________________
Echo Nothing else to do now
echo ______________________
pause>nul
```


----------



## gurutech (Apr 23, 2004)

I don't think you need the : character in your "goto" statements.

ie. You have "goto :end", but I believe you only need "goto end".

You still need the : for that section of the batch file.

You could also use "errorlevels" to "exit" the batch file based on the choice. Check out "choice /?" for more details. You will need to place your error level statements in decreasing value, ending at "0".

ie:
if errorlevel 4 goto choice4
if errorlevel 3 goto choice3
if errorlevel 2 goto choice2
if errorlevel 1 goto choice1
if errorlevel 0 goto choice0


----------

