1.

Solve : Basic loop with choice issue?

Answer»

Hey guyz,

ive made a basic loop with choice but i wanted to add an extra option in there, i used the script from the site which is

echo off
cls
:start
echo This is a loop
set choice=
set /p choice="Do you wish to restart? Press 'y' and enter for Yes: "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='y' goto start

and i modified it to look like this

echo off
cls
:start
echo This is a loop
set choice=
set /p choice="Do you wish to restart? Press 'y' and enter for Yes, or 'n' to exit: "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='y' goto start
if '%choice%'=='n' exit

what IM trying to do is only exit when 'n' is ENTERED, although with the basic site script if any key is entered besides 'y' it quits.
im trying to figure out how to quit only on 'n' command and any other commands would remain useless...

tough question, haha i KIND of gave myself a headache thinking about itSo what do you want to happen if choice is not y or n?  The script is exiting (ending) because there is nothing more for it to do.

You could try:
if '%choice%'=='n' exit
goto start

then it will loop if choice is anything but n

Good luck
  this is how im doeing loops

Code: [Select]echo off
cls
:MAIN
echo This is a loop
set choice=
set /p choice="Do you wish to restart? Press 'y' and enter for Yes, or 'n' to exit: "
if /I '%choice%' equ 'y' goto start
if /I '%choice%' equ 'n' exit
goto MAIN
:START
echo Starting...
pause >nulThey were both of great use, considering i didnt really ask the question in english

thanks guyz !



Discussion

No Comment Found