Version 6 of do..while

Updated 2005-10-17 08:59:08 by dkf

See do...until in Tcl

See also while...wend in Tcl

There is a difference between do..until and whild..wend. By do..until the statment is executeted at least once

We can simulate such behaviour in Tcl by:

   while 1 {
      # ..statement
      if {!expresion} break
   }

DKF: Try this:

 proc do {body keyword expression} {
    if {$keyword eq "while"} {
       set expression "!($expression)"
    } elseif {$keyword ne "until"} {
       return -code error "unknown keyword \"$keyword\": must be until or while"
    }
    set condition [list expr $expression]
    while 1 {
       uplevel 1 $body
       if {[uplevel 1 $condition]} {
          break
       }
    }
    return
 }

Category Control Structure