Substitution in an ‘if’ statement in tcl

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Substitution in an ‘if’ statement in tcl

  • Creator
    Topic
  • #48663
    Keith McLeod
    Participant

      I have 2 expressions, one that works and one that doesn’t. Any idea why the second test doesn’t work? The Day variable represents Sun Mon Tue…. I loop through the hours for each day Sun(0) Sun(1)….Sat(23). The if statement determine the beginning or end of a gap.

      This works:

      if {[set ${Day}($i)] != 0 && [expr [set ${Day}([expr $i+1])] + [set ${Day}([expr $i+2])] + [set ${Day}([expr $i+3])]] == 0} {

      This doesn’t

      if {$i > 2 && [set ${Day}($i)] != 0 && [expr [set ${Day}([expr $i-1])] + [set ${Day}([expr $i-2])] + [set ${Day}([expr $i-3])]] == 0} {

    Viewing 0 reply threads
    • Author
      Replies
      • #59322
        Anonymous
        Participant

          Keith,

          The problem probably stems from the [$i > 2] part of the statement.  Since this is regarded as an arithmetic expression, you may need to have it read as [expr $i > 2].  

          Hope this helps…

          Thomas G. Rioux

      Viewing 0 reply threads
      • The forum ‘Cloverleaf’ is closed to new topics and replies.