Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
The following code works as expected-
it loops for user's input and detects <ret>, Y/y or N/n:---------------
@echo off
setLocal EnableDelayedExpansion:inputloop
set cho=
set /p "cho=>"
if !cho!'==' goto return
if /i %cho%==y goto yes
if /i %cho%==n goto no
goto inputloop:return
echo return
pause
goto :eof:yes
echo yes
pause
goto :eof:no
echo no
pause
goto :eof
---------------But the code no longer behaves after I add a nested IF structure. Y/y and N/n still work as before, but <ret> now seems to skip the 'goto return' and heads straight for :eof.
How could this be? Help!
---------------
@echo off
setLocal EnableDelayedExpansion:inputloop
set cho=
set /p "cho=>"
if !cho!'==' (
goto return
) else (
if /i %cho%==y (
goto yes
) else (
if /i %cho%==n (
goto no
) else (
goto inputloop
)
)
):return
echo return
pause
goto :eof:yes
echo yes
pause
goto :eof:no
echo no
pause
goto :eof
---------------

@echo off
setLocal EnableDelayedExpansion:inputloop
set cho=
set /p "cho=>"
if !cho!'==' (
goto return
) else (
if /i !cho!==y (
goto yes
) else (
if /i !cho!==n (
goto no
) else (
goto inputloop
)
)
):return
echo return
pause
goto :eof:yes
echo yes
pause
goto :eof:no
echo no
pause
=====================================
If at first you don't succeed, you're about average.M2

It works! Thanks, Mechanix2Go.
Looks like I can't mix !cho! and %cho%. But why is that? By the look of it, I'm guessing that !cho! is "inline substitution" (?), while %cho% is simply a variable? But then again, why can't they mix?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |