Reputation: 13
So basically I have been looking all over the internet trying to find a good way of doing this: Create a limited loop in my batchfile program. I have found no answer. An example I tried is this:
@echo off
echo Hello this is your program.
pause
set i= 0
: test
set i= i + 1
if %i% == 5 goto exit
goto test
: exit
echo good
pause
exit
I later found out that I can't just make the "i" variable like that. When I try to make it a variable it makes me put an input in the command prompt of the program and I don't want that. I want this to run maybe 5 times, then quit running and go to something else. If you can answer and help me thanks.
Upvotes: 1
Views: 34
Reputation: 57784
for %i in (1 2 3 4 5) do echo good %i
results:
Okay, here it is in the form you want. This ran on Windows XP:
It depends on set /a
to evaluate the right side as an arithmetic expression. More than addition is supported. Type help set
to learn more.
Upvotes: 0