0

I don't understand why the result of echo is empty instead of 10001\n10002...

for /l %%x in (1, 1, 10) do (
   set i=%%x
   set startport=10000
   set /a "port=%startport%+%i%"
   echo %port%
)
  • 1
    A few basic best practices. 1) Don't assign the value of the `FOR` variable to an environmental variable. 2) You don't need to use the percent symbols for environmental variables in a `SET /A` command. example: `SET /A "port=startport + %%x"` – Squashman Apr 07 '21 at 17:06
  • 1
    Regardless of that why not use: `FOR /L %%x in (10000,1,10) do`. That seems like a much more efficient way to code it. Then you don't need the `SET /A` command. – Squashman Apr 07 '21 at 17:07
  • And because you are inside a parenthesized code block you will need to use Delayed Expansion to see the value of variables that are created or changed inside the code block. Please see [Variables are not behaving as expected](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected) – Squashman Apr 07 '21 at 17:09

0 Answers0