Jump to content

Recommended Posts

Posted

Try this:

 

[noparse]@echo off
set max=.ooo
set count=.
:LOOP
echo hi there
set count=%count%o
if not %count%==%max% goto LOOP
set max=
set count=
echo complete[/noparse]

 

set max=.ooo <-- 3 o's is your repeat.

Posted

Other option "think it should work" is simply making a list and going through it like:

 

for %a in (1,2,3) do echo "test"

 

Think that should work, but can't run BATs locally :(

 

Steve

Posted (edited)

The /L switch in 'FOR' is your best bet.

 

FOR /L %variable IN (start,step,end) DO command [command-parameters]

 

The set is a sequence of numbers from start to end, by step amount.

So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would

generate the sequence (5 4 3 2 1)

 

example

@echo off
for /L %%n in (1,1,3) do (
echo I'm in a loop!
echo This is loop number %%n
echo Oh yes.
if %%n EQU 3 (echo THIS IS THE LAST TIME I SHOULD RUN!!!)
)

 

will give you

 

I'm in a loop!

This is loop number 1

Oh yes.

I'm in a loop!

This is loop number 2

Oh yes.

I'm in a loop!

This is loop number 3

Oh yes.

THIS IS THE LAST TIME I SHOULD RUN!!!

Edited by jinnantonnixx

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...