Trouble with Relational Expression

Dec 2, 2008
226
2
Canada
I am currently using TCC 13.04.63 and have noticed the following:

c:\> set i=1 & do while (%i != 10 .or. %i == 1) (echo %i & set i=%@inc[%i]) & echo %i
1
2
3
4
5
6
7
8
9
10

c:\> setlocal & set i=1 & do while (1==1 .and. %i != 10) (echo %i & set i=%@inc[%i]) & echo %i & endlocal
1
2
3
4
5
6
7
8
9
10


c:\> set i=1 & do while (%i != 10) (echo %i & set i=%@inc[%i]) & echo %i
1

Is there something wrong with how relational expressions are evaluated?
 
Dec 2, 2008
226
2
Canada
Yes, but the parentheses shouldn't change how it is evaluated, parentheses define precedence so %i != 10 is equivalent to (%i != 10) because the parentheses should have no effect.

Craig
 
May 20, 2008
3,515
4
Elkridge, MD, USA
In general parentheses around a logical expression (any combination of relational expressions is a logical expression) are transparent, but the parsing of the single-line DO statement may have quirks... They may be considered as containing the command to be performed each time through the loop.
 
May 20, 2008
11,404
99
Syracuse, NY, USA
In general parentheses around a logical expression (any combination of relational expressions is a logical expression) are transparent, but the parsing of the single-line DO statement may have quirks... They may be considered as containing the command to be performed each time through the loop.
That's right; it's peculiar to DO. DO expects the <command> to be in the parentheses. In your examples that work, the logical keywords (.or., .and.) inside the parentheses are a tip-off that the parentheses are for another purpose. There's no such clue if you use (%i !=10).
 
Similar threads
Thread starter Title Forum Replies Date
vefatica Trouble piping Support 3
R Trouble with @REGSET[] Support 6
J Trouble with @full[] function. Support 3
old coot TC DIR command has trouble on my SSD Support 2
S Trouble accessing results of forum search Support 2
vefatica Trouble closing TCMD Support 0
M Trouble loading alias list Support 2
Jay Sage CascadePoint Fails to Install (And Some Trouble with TCMD) Support 2
S PDIR has trouble processing filenames with embedded percent sign Support 3
Roedy trouble with COPY /U Support 7
Juanma Barranquero Ctrl-C trouble Support 1
J trouble redirecting output to environment variable Support 7
M Just a verification regarding "Iff" and both "status test(s)" and "relational expression(s)"... Support 3
D How to? Use regular expression with REN? Support 2
R v25 Regular Expression Analyser Support 2
vefatica SET /A var=expression=digits Support 3
D conditional expression: force numeric Support 6
D Catching the result of an evaluated script expression Support 0
rps Documentation Regular expression syntax link broken Support 1
WadeHatler Fixed Breaking change in Expression evaluation (.and.) in v17 Support 6
Joe Caverly Conditional Expression Test of @SFN Support 4
M How to? Do a particular regular expression... Support 8
JohnQSmith Regular expression groups Support 15
A How to? filter text stream with a regular expression Support 11
Phileosophos Can FFIND match file names with a regular expression? Support 19
fpefpe regular expression -- caseless Support 3
nickles Regular expression FOR/DIR Support 2
B @PERL[expression] definition? Support 2

Similar threads