• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 51
  • Last Modified:

Batchscript For Loop dynamic repeats


i'm looking for a solution to run a For Loop a certain amount of times, which i set before in a variable.

i did something like this:
set /p count=Count:

for %%i IN (0,1,%%count%%) do

Open in new window

But no matter what i set the variable to, the code runs exact 3 times.
Where is my mistake ?
Jonas Huber
Jonas Huber
1 Solution
That's because of the double percent signs around the variable, and because you need the /L option for a count loop.
Without the /L, the loop will run once for each of the elements passed inside the brackets, hence the three iterations.
set /p count=Count:
for /L %%i in (0, 1, %count%) do (
	echo %%i

Open in new window

Jonas HuberAuthor Commented:
Ok thanks that worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now