Question Bat file problems. Please help!

Gabrielnigme20

Reputable
May 27, 2019
14
0
4,520
ok.. So I tried to create a bat file that would open a menu the amount of times as you inputted a number ex.

set /p opt= Amount:

Then after that you now have the %opt% set to the "amount" you inputted.
Then the way the menu works is like this..

:start1
if %opt%==0 goto end
:start2
start test.bat
set %opt%-1
if %opt%>0 goto start2

goto end

so that's pretty much the whole script though the marked part doesn't seem to work... Why is that PLEASE HELP!

The entire script...

@Echo off
title screen power...
mode 150
color a

:start
echo please enter the amount of Starts you want.
echo.
set /p opt= Amount:
if %opt%==0 goto end

:begin
start test.bat
set %opt%-1
if %opt%>0 goto begin
goto end

:end
 

gardenman

Splendid
Moderator

britechguy

Commendable
Jul 2, 2019
1,479
243
1,340
GTR is greater than, not equal to.

This loop is arranged to keep going back to begin each time so long as the value of the variable opt is greater than zero. Once it has been decremented to zero, it goes to end. (And it would have done that anyway, with out the "go to :end" statement, given it's position in the script.

One of the best, and most comprehensive, websites when it comes to scripting languages is https://ss64.com/. It's got sections dedicated to many of the most common ones, including command prompt (CMD): https://ss64.com/nt/

Specific to your question, have a look at the compare-ops in the documentation of the IF statement: https://ss64.com/nt/if.html