How to? Logic in aliases...

#1
As was pointed out to me in another thread program logic can be placed into aliases. I didn't assume/know this because I really didn't think of logic "commands" as "commands" in the usual sense; i.e. in TCC "IF", "ELSE", "DO" and "ENDO" for instance are not just logic elements (as they are in most other languages), they are actually commands. So testing this out I came up with the following alias:
Code:
Alias Logic=`SetLocal & Set C=0 & Set I=1 & Do While %I LT 65536 & Set /A I+=I & Set /A C+=1 & EndDo & Echo C: %C I: %I & EndLocal`
Unfortunately, executing this alias has the following result:
Code:
[Z:\]logic
Usage : DO [n | FOREVER]
2
1
TCC: Unknown command "EndDo"
C: 1  I: 2
 
[Z:\]
So turning the body of the above alias into a batch file:
Code:
[Z:\]Type LogicI.btm
SetLocal & Set C=0 & Set I=1 & Do While %I LT 65536 & Set /A I+=I & Set /A C+=1 &
EndDo & Echo C: %C  I: %I & EndLocal
 
[Z:\]LogicI
SetLocal
Set C=0
Set I=1
Do While %I LT 65536
^C
 
Cancel batch job Z:\LogicI.btm ? (Y/N/A) : A
 
[Z:\]
a different error (apparently an infinite loop) but still an error.

However putting every statement on a single line:
Code:
[Z:\]Type LogicII.btm
@Echo Off
SetLocal
Set C=0
Set I=1
Do While %I LT 65536
  Set /A I+=I
  Set /A C+=1
EndDo
Echo C: %C  I: %I
EndLocal
 
[Z:\]LogicII
C: 16  I: 65536
 
[Z:\]
The only "changes" were the addition of the "@Echo Off" commandand separation of the individual commands by linefeeds rather than command separator characters.

And even something like "Do 16" is not valid because "EndDo" is not valid in an alias:
Code:
[Z:\]Type LogicIII.btm
@Echo Off & SetLocal & Set C=0 & Set I=1 & Do 16 & Set /A I+=I & Set /A C+=1 & End
Do & Echo C: %C  I: %I & EndLocal
 
[Z:\]LogicIII
TCC: Z:\LogicIII.btm [1]  Unknown command "EndDo"
C: 1  I: 2
 
[Z:\]
So does this mean the only logic "command" allowed in an alias is the "If"?
 
#2
Your problem is that you ignored the CAVEAT on the help page for the DO command - DO and ENDDO must be on separate lines. It is possible to use the "single line DO" in an alias, but it executes a command group, i.e., the command(s) must be enclosed in parentheses (command).
 
#3
Thank you, Steve. But my problem isn't that I "ignored" the CAVEAT, it's that I didn't see it because I'm half blind and therefore tend to automatically (as in subconsciously) read the minimum amount of stuff that I think I need to read; and this especially a problem for old material I have looked at multiple times in the past but didn't remember all of the details (I have also been diagnosed as having very bad memory). But the bottom line is that is good to know.