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?

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.

It wouldn't break anything, except good style. But it would come in
mighty handy... Just wondering how much of a flame I'd get for even
muttering such evil thoughts... ;)

That is *unusual*, one might even say *unique* -- I've never seen it in any language.

If you use another "keyword" other than else, it should be trivial to implement as a Tcl proc. You would want to read the man pages for if and uplevel before attempting to do the implementation.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.



Relevant Pages

  • 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
    ... of the conditions match, but not in the "else" case. ... 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, ...
    (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)