FN-GM Posted August 4, 2011 Posted August 4, 2011 In a batch file is it possible to set it to loop say 3 times only? Thanks
mattx Posted August 4, 2011 Posted August 4, 2011 In a batch file is it possible to set it to loop say 3 times only? Thanks Yes it is.
eversonj90 Posted August 4, 2011 Posted August 4, 2011 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.
Steve21 Posted August 4, 2011 Posted August 4, 2011 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
jinnantonnixx Posted August 4, 2011 Posted August 4, 2011 (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 August 4, 2011 by jinnantonnixx
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now