Can someone please give me an easy to understand overview of the 'for' command
Thanks,
Rileyh
help with 'for' command
Moderator: DosItHelp
Re: help with 'for' command
Rileyh wrote:Can someone please give me an easy to understand overview of the 'for' command
Thanks,
Rileyh
No one's going to explain this huge command to you. You can understand the "for /f" part here.
I'll also quickly explain the "for /l" part. This one is easy.
Code: Select all
for /l %%a in (0;5;10) do (
echo %%a
)
This is much similar to the C-type FOR loop.
"%%a" is your output variable. Every time your code loops, it sets "%%a" to something. "for /l" uses the whole "(begin;increment;stop)" thing. In C-type languages, it's usually "(being;stop;increment)", so "for /l" is similar, but not the same.
"0" is where we are starting. So we are setting "%%a" to "0". Now every time the code loops (a loop is done once all lines of code in between the do() is finished) it will add on to %%a by the increment. The increment is "5". So every time it loops, it add 5 to %%a. Now we are stopping once it's greater than or equal to "10". That is the "stop". So when we say "0;5;10", we are saying "set %%a to 0;add 5 to it for each loop;stop when %%a >= 10".
This is what it will output:
Code: Select all
0
5
10
Re: help with 'for' command
Thanks nitt,
This has been helpful to me.
After looking it up on "cmd.exe" i saw it was extremely long and conveluted to explain.
Sorry for such an ask.
THanks,
Rileyh
This has been helpful to me.
After looking it up on "cmd.exe" i saw it was extremely long and conveluted to explain.
Sorry for such an ask.
THanks,
Rileyh
Re: help with 'for' command
Hi nitt,
I tested the code you posted and it didn't work.
I placed a pause after each line and it still didn't turn up as anything.
I'm not sure why though
Rileyh
I tested the code you posted and it didn't work.
I placed a pause after each line and it still didn't turn up as anything.
I'm not sure why though
Rileyh