Whodeyy1234
Whodeyy1234

Reputation: 13

How can you create a limited loop in a batchfile program?

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

Answers (1)

wallyk
wallyk

Reputation: 57784

for %i in (1 2 3 4 5) do echo good %i

results:

enter image description here

Okay, here it is in the form you want. This ran on Windows XP:

enter image description here

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

Related Questions