Re: if else else



Fredderic wrote:
I know this idea will disturb many purists, but .....

I was wondering if there's any compelling reason not to allow a
secondary-else clause in the [if] command, apart from the fact that
it's generally just not done?

Potential for confusion.


There have been numerous cases where I've had a "if ... elseif ...
elseif ... else" structure, where I've needed to do some cleanup if any
of the conditions match, but not in the "else" case. A secondary else
that matches if the regular one didn't (ie. if any of the regular
clauses DID match) would be handy for such cleanup (or in this case,
follow-up) code.

I don't think I've ever needed this myself, but if I did want such a thing, I'd probably implement it this way:

interp alias {} once {} foreach _ _

Which you can then use in simple fashion:

once {
if {$conda} {
...
} elseif {$condb} {
...
} else {
break
}
common cleanup
}

-- Neil
.



Relevant Pages

  • Re: if else else
    ... of the conditions match, but not in the "else" case. ... that matches if the regular one didn't (ie. if any of the regular ... mighty handy... ...
    (comp.lang.tcl)
  • if else else
    ... of the conditions match, but not in the "else" case. ... that matches if the regular one didn't (ie. if any of the regular ... mighty handy... ...
    (comp.lang.tcl)
  • Re: if else else
    ... clauses DID match) would be handy for such cleanup (or in this case, ... } elseif { ... set ret [uplevel 1 $script] ...
    (comp.lang.tcl)
  • Re: if else else
    ... clauses DID match) would be handy for such cleanup (or in this case, ... mighty handy... ... "cleanup" code into it's own proc and call that proc from within each ...
    (comp.lang.tcl)
  • Re: if else else
    ... elseif ... ... clauses DID match) would be handy for such cleanup (or in this case, ...
    (comp.lang.tcl)