A little problem with LEAVE and COMMENT

Demoscript to show the problem:
Code:
Do z = 0 To 10
    If %@EVAL[%z% MOD 2] EQ 0 ITERATE
        If %z% EQ 7 LEAVE
    Echo Z:%z
COMMENT
  @SUBSTR[string,start,length]
 :  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.
ENDCOMMENT
  EndDo
After reaching the LEAVE it seems, that parser will go another way, because it will show error messages:
2407

"No closing quote."
 
May 20, 2008
11,388
99
Syracuse, NY, USA
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.
 

rconn

Administrator
Staff member
May 14, 2008
12,340
149
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
Thread starter Title Forum Replies Date
M A new problem that has actually got me a little panicky... Support 10
MickeyF A little help with @REREPLACE Support 6
M Little bug, big consequences .. Support 6
M An oddity that's a little bit scary... Support 6
vefatica ZIP /U a little screwy Support 9
R How to? i need a little help Support 3
M A little bit of strangeness with @Char... Support 3
L A little startup help from an old CLI guy please. Support 14
Peter Bratton Another little bug? Support 1
A TCMD 11 little bugs Support 4
H I need a little help. Support 4
C Some little observations Support 16
Dick Johnson Weird Color Problem Support 8
fishman@panix.com Problem with 27.15 Support 2
M Problem with VSDevCmd.bat in VS 16.7.3 Support 0
R Problem with @INT[ value] in V26 Support 9
M Selecting test "off by one" problem in Take command Support 4
Alpengreis UTF-8 problem in TCC related to Python Support 7
K_Meinhard Small problem in german IDE 26 Support 3
B Problem with color in nested shells Support 1
Joe Caverly Problem creating and switching to a DESKTOP Support 9
vefatica Another popup problem Support 10
Alpengreis ffind dialog (/W) problem Support 4
Alpengreis [TCMD v25.00.24] Small space problem with the DE translation in Prefs-GUI Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6
A Problem with functions @int @decimal and identifying Powershell as a shell. Support 12
B IF command problem in tcexit.btm Support 9
fishman@panix.com Problem at Startup of TCC Support 3
P Problem with SFTP copies Support 7
P Problem with FTP copies Support 10
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
R Problem with %_do_loop in nested do loops Support 2
fishman@panix.com New Problem with later Windows 10 Support 10
M Handling of %~I problem Support 4
WinLanEm FOR problem Support 18
K Problem With SCRPUT /u Support 3
vefatica What's TCMD's problem with ^e[0m? Support 13
Peter Murschall IDE: RTL with non-English resources-problem is back in Build 28 Support 4
rps Regex problem: \xnn not recognized as a hex character Support 0
rps PRIORITY LOW problem Support 1
old coot Regex problem: \xnn not recognized as a hex character Support 12
vefatica Another problem with build 22. Support 3
Alpengreis [23.x] Download-Problem Support 2
S Problem with " Support 3
C Problem navigating forums Support 11
x13 Problem listing repository files using DIR http(s)://... Support 8
Joe Caverly Problem with TEE in v22 Support 2
Alpengreis Problem with thousands delimiter and colors Support 17
M Take Command 18, migrating to another machine, license problem. Support 1
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2

Similar threads