Trouble with Relational Expression

Dec 2, 2008
212
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
212
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,520
3
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
9,274
62
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).