By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

A little problem with LEAVE and COMMENT

Demoscript to show the problem:
Do z = 0 To 10
    If %@EVAL[%z% MOD 2] EQ 0 ITERATE
        If %z% EQ 7 LEAVE
    Echo Z:%z
 :  An older version of @INSTR.
      If the length is omitted, it will default to the remainder of string. 
!!! If string includes commas, it must be quoted with double quotes ["] or 
!!! back-quotes [`], or each comma must be preceded by an Escape character. 
!!! The quotes count in calculating the position of the substring. 
     @INSTR, which has string as its last parameter, does not have this restriction.
After reaching the LEAVE it seems, that parser will go another way, because it will show error messages:

"No closing quote."
The help says:
Both COMMENT and ENDCOMMENT must be entered as the only commands on their respective lines, and cannot be included in a command group.

I think being inside a DO loop qualifies as being inside a command group. The same thing will happen inside IFF/ENDIFF.
The problem is with the single back quote in one of your COMMENT lines.

When the parser sees the LEAVE, it scans the batch file looking for the first ENDDO. The parser does not try to evaluate each line (which would make the LEAVE useless), it just reads them and processes them looking for aliases & variable expansion, then checks to see if the first argument is ENDDO. When the parser reaches the line with the single back quote, it displays an error, then continues looking for the ENDDO, eventually finds it, and continues normal processing following the ENDDO.

I don't really want to do another embedded parser just to handle a COMMENT block within a DO (which doesn't seem to provide anything particularly useful). I'll think about turning off parsing error messages while looking for an ENDDO. In the meantime, escape your back quote.
Yeah, that's exactly what I've been scoffing at. The "problem" did not appear until I inserted the LEAVE and the condition also occurred. Now that I know this, I will avoid COMMENT blocks and use the tried and tested double colons.
Thanks for clarification Rex.
Thanks Rick, but meanwhile I have realized that BTM is not a complete programming language
like xyz-BASIC, C, etc. .
Rex respective JPSOFT are constantly dragging the legacy of CMD/BATCH and trying to stay compatible,
see also the thread WAD - rem does not work correctly.
As comfortable and convenient as these block instructions are, I can live very well with the double colons
and place my Comments wher I want to have them :cool:

Similar threads