Stuck on if else

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
yelayak
Posts: 1
Joined: 29 Jul 2017 11:59

Stuck on if else

#1 Post by yelayak » 29 Jul 2017 12:03

Hello,

I am new here and here is my my problem. I want to jump back and forward between "labels" that i defined. I go and get back from the ":Kitchen" but other are not working. What am i missing?

:Corridor

echo -------: Kitchen
echo -------: Restroom
echo -------: Freezer
set /p LOOK=LOOK :

if %LOOK%==Kitchen (goto :Kitchen) else (goto :Corridor)
if %LOOK%==Restroom (goto :R2) else (goto :Corridor)
if %LOOK%==Freezer (goto :R3) else (goto :Corridor)

Pause >nul

:Kitchen

echo Kitchen

set /p Back= Type Back to turn corridors :

if %Back%==Back (goto :Corridor) else (goto :Kitchen)

Pause

:Restroom

echo Restroom

set /p Back= Type Back to turn corridors :

if %Back%==Back (goto :Corridor) else (goto :Restroom)

Pause

:Freezer

echo Freezer

set /p Back= Type Back to turn corridors :

if %Back%==Back (goto :Corridor) else (goto :Freezer)

Pause

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Stuck on if else

#2 Post by aGerman » 29 Jul 2017 13:14

Code: Select all

if "%LOOK%"=="Kitchen" (
  goto :Kitchen
) else if "%LOOK%"=="Restroom" (
  goto :R2
) else if "%LOOK%"=="Freezer" (
  goto :R3
) else goto :Corridor

But where are the labels :R2 and :R3 you want to jump to?

FWIW With all those GOTO criss-crossing you will lose track of the code quite soon.

Steffen

Post Reply