"Alan" <> wrote in message
news:2557b37a-4355-4ffc-a72e-...
>> See the difference?
>
> Yes. But why?
>
In this batch file
@echo off
set Number=
for /L %%a in (1,1,10) do (
set Number=%%a
echo Number=%Number%
)
the following lines of code
for /L %%a in (1,1,10) do (
set Number=%%a
echo Number=%Number%
)
are treated as one single line of code. The command processor reads this
"single" line, then resolves its variables. Since the variable "%Number% is
set to "nothing" at the beginning, it remains at "nothing". To force a
rescan, you must do two things:
- You must enable "delayed expansion"
- You must replace the %Number% with !Number!.
|