1.

Solve : need an echo loop?

Answer»

hey guys.

we have a long long console output from a job we are doing. what i would like is a simple loop that will echo "next command" or something similar 40 times or so

this is so that, rather than squinting my EYES TRYING to find the command, i can easily identify where the commands have been issued, and at what command it ran into trouble.
So for instance my bat file would read:

command
loop
command
loop
command
loop

and so on.


does anyone know a simple loop i could use to repeat 40 lines of text to the screen plz?

regards,
redd .Is it the same command each time? Maybe something like this...

for /L %%A in (1,1,40) do (
echo next command
[command]
)

FOR /L syntax: FOR /L %%var in (start, step, end) do...



cheers man!

yes the same command each time, its just like a bookmark really, so i don't have to go hunting for the commands.

I'll give that a try )This seems to be closed already, but an alternative solution would be
Code: [Select]@echo off
setlocal EnableDelayedExpansion
set /a foo=1
:A
if %foo% leq 40 (
ping 192.0.2.2 -n 1 -W 500 >nul
echo looped !foo! times
set /a foo=!foo!+1
goto A
)
pause
cls
exit
)You could modify the "ping 192.0.2.2 -n..." by changing the 500 to another number.
500 represents the milliseconds to wait.
So 1000 is one second, 10000 is ten, and so on.
I just put the wait there so it didn't just say the whole 40 times instantly.
Take that line out if you feel you need to.1. You left a final parenthesis

2. You didn't need delayed expansion

Code: [Select]@echo off
set foo=1
:A
ping 192.0.2.2 -n 1 -w 500 >nul
echo looped %foo% times
set /a foo+=1
if %foo% leq 40 goto A
pause
cls
exit

3. What's wrong with using FOR /L?

Quote

Quote from: Salmon Trout on July 16, 2013, 10:49:52 AM
1. You left a final parenthesis

2. You didn't need delayed expansion

Code: [Select]@echo off
set foo=1
:A
ping 192.0.2.2 -n 1 -w 500 >nul
echo looped %foo% times
set /a foo+=1
if %foo% leq 40 goto A
pause
cls
exit

3. What's wrong with using FOR /L?


Nothing is wrong with FOR /L, I just... find it hard to figure out... ummm xD
And excuse me for the flaws. I was half asleep at 6 AM.
Quote from: jofspades on July 16, 2013, 02:57:30 PM
And excuse me for the flaws. I was half asleep at 6 AM.

This is a help forum, not a chat room. You should only post code that you have actually tested.


Discussion

No Comment Found