Trouble with Relational Expression

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Dec 2, 2008
209
2
Canada
#1
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
209
2
Canada
#3
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
 
#4
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.
 
#5
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).