1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trouble with Relational Expression

Discussion in 'Support' started by cgunhouse, Jan 17, 2013.

  1. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    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?
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    Do not use parentheses around the conditional expression.
    Code:
    do while %i NE 10 ( command )
     
  3. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    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. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    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).
     

Share This Page