Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Trouble with Relational Expression

Dec
233
2
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?
 
Do not use parentheses around the conditional expression.
Code:
do while %i NE 10 ( command )
 
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
 
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.
 
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

Back
Top