How to loop a batch script only a certain amount of times

batch-fileecholoops

How do I loop a batch script only a certain amount of times (x10 or something)?
If the code was:

@echo off                                                                     
:loop1                                                                              
Start taskmgr.exe                                                       
Goto loop                                                                         
:loop2                                                                             
Start cmd.exe                                                                 
goto loop2     

How can loop loop1 and few times and go to loop2?

Any helpful answer would be appreciated 🙂

Best Answer

if you open a command window and type FOR /? it will give you the command you are looking for.

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)