<?xml version="1.0" encoding="windows-1252"?>
<node id="136139" title="(jeffa) 2Re: (Ovid - Why I love nested If-Else blocks)" created="2002-01-03 22:05:02" updated="2005-07-27 12:19:45">
<type id="11">
note</type>
<author id="18800">
jeffa</author>
<data>
<field name="doctext">
You have a point and i do agree, but what happens when you 
scale your example up? That's what i am talking about here.
Consider this:
&lt;code&gt;
if ( $foo &gt; 7 ) {
 if ( $bar ) {
  bar_func( $foo );
 }
 elsif ( $baz ) {
  baz_func( $foo );
 }
 elsif ( $qux ) {
  baz_func( $foo );
 }
}
elsif ( $foo &lt;= 7 ) {
 if ( $bar ) {
  other_bar_func();
 }
 elsif ( $baz ) {
  other_baz_func();
 }
 elsif ( $qux ) {
  other_qux_func();
 }
}
&lt;/code&gt;
Get's hairy quick. At that point, i would definetaly
try a dispatch table with sub references.
Now, to _really_ go out on a limb,
how about a [goto] as a replacement for your first
example, since you are only concerned with calling
the subs if one condition is true:
&lt;code&gt;
goto SKIP unless $foo &gt; 7;

if ($bar) {
   bar_func($foo);
}
elsif ($baz) {
   baz_func($foo);
}

SKIP:
# more code
&lt;/code&gt; 
Notice i didn't get rid of the outer if, i just seperated
it from the inner if. Even though i use a goto, it looks
more readable to me, simply because the indention level. Well, it looks more readable as long as i don't have to
scan more than 10 lines to find where the goto is going!
Besides, if this
were inside a sub, i could replace the goto with return.
&lt;p&gt;
BUT ... I do agree that your first example is more
readable than your second, and is much better form
than my goto solution.
&lt;p&gt;
Did i just use a [goto]?!?
&lt;p&gt;jeffa&lt;/p&gt;
&lt;font size=1&gt;
&lt;pre&gt;
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)
&lt;/pre&gt;&lt;/font&gt;</field>
<field name="root_node">
136097</field>
<field name="parent_node">
136122</field>
</data>
</node>
