Friday, October 19, 2007

Label at the End of Block

One thing I hate about batch file is, there is no real language definition you can refer to (or is there?).  So a lot of things I have to find out by myself the hard way.

Here's an example of this:

@echo off

for /L %%i in (1,1,10) do (

  if %%i GEQ 5 goto :NOPRINT

  echo %%i

  :NOPRINT

)

This gives an error saying that ") was unexpected at this time".  It is obvious what this means, and it is obvious how to fix it.  Just put a comment between the label and the closing bracket.

@echo off

for /L %%i in (1,1,10) do (

  if %%i GEQ 5 goto :NOPRINT

  echo %%i

  :NOPRINT

  REM can't have label immediately preceding closing bracket
)

I know this is not really anything useful, just a rant, that's all.

No comments: