The reason that it's a broken label can be demonstrated by this code:
@ECHO On
SETLOCAL
GOTO fred
ECHO miss this 1
:fred
GOTO :bill
ECHO miss this 2
:bill
GOTO ::charlie
echo miss this 3
::charlie
ECHO all done!
GOTO :EOF
That is, a leading :
indicates a label, but the label-name itself may not start :
. Now whether :label:with:colons
is a valid label, I'll leave to the enthusiastic experimenter. I'd prefer to keep to a simple rule - no colons in label-names.
As for the no-labels-in-code-blocks rule, remember cmd
's history. At one time, code-blocks were not allowed. It's a simple-minded processor which may have learned a lot since its inception. It wants to maintain backward-compatibility, so suppose we come across some common constructions within a block:
goto label, goto :label, call label, call :label
this leaves us with a nightmare of possible return-paths and interpretation possibilities. Does goto outofblock
terminate the block? Does goto inblock
terminate the iteration?
Hence, the simple-minded rule, no labels in blocks. I remember jeb worked out a set of rules where labels can be used, which was interesting. Here's a video