After some testing I find that a label only fails when the label is the last line of the do loop
Code: Select all
@echo off
for /f "delims=" %%a in ("text") do (
set var=%%a
goto :label
:label
)
) was unexpected at this time.
But this works to get the first line of the file and keeping the code within the parentheses.
Code: Select all
@echo off
for /f "delims=" %%a in (file.txt) do (
set var=%%a
goto :label
:label
rem
)
echo %var%
This works too, with a double full-colon:
Code: Select all
@echo off
for /f "delims=" %%a in (file.txt) do (
set var=%%a
goto :label
:label
::
)
echo %var%
The same thing holds true with casual parentheses - this generates an error but adding a statement after the label allows it to work.
Code: Select all
(
set var=text
goto :label
:label
)
I had read someone say once that you can't have a label in a for in do loop and I didn't actually test it, but remembered what I had read.
It goes to show how dearly held beliefs are not always in fact totally true.
