<?xml version="1.0" encoding="windows-1252"?>
<node id="301423" title="Re: Re: Re: Re: Perl Idioms Explained: &amp;&amp; and || &quot;Short Circuit&quot; operators" created="2003-10-22 19:30:23" updated="2005-07-07 15:24:48">
<type id="11">
note</type>
<author id="108447">
demerphq</author>
<data>
<field name="doctext">
&lt;!--
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;code&gt;&lt;/code&gt;
&lt;i&gt;&lt;/i&gt;
&lt;b&gt;&lt;/b&gt;
&amp;#91; &amp;#93; 
--&gt;
&lt;p&gt;
Well, what I mean is that I dont see how in C the conditional is only evaluated once. I dont know enough about how C implements a case statement to say for sure But i dont see how a case statement could be implemented in such a way without adding a lot of code to the statement, which would potentially be far more expensive than converting it to a series of conditionals. For instance something like this
&lt;/p&gt;
&lt;code&gt;
switch (val) {
  case 1 : handle_case1; break;
  case 2 : handle_case2; break;
  case 5 : handle_case5;
  case 10: handle_case10;
  default: handle_default; 
}
&lt;/code&gt;
&lt;p&gt;
I would guess would get converted to something like
&lt;/p&gt;
&lt;code&gt;
if (val == 1) {
  handle_case1;
} elsif (val == 2) {
  handle_case2;
} else {
  if (val == 5) {
    goto CASE5;
  } elsif (val == 10) {
    goto CASE10;
  } else {
    goto DEFAULT;
  }
CASE5:   handle_case5;
CASE10:  handle_case10;
DEFAULT: handle_default;
}
&lt;/code&gt;
&lt;p&gt;
Or something like it. I just dont see how it could be handled otherwise. Perhaps the fact that it only operates on ints means that there is a neater optimisation. But if you extend switch to handle strings as it does in pascal then I think the situation becomes even more difficult.
&lt;/p&gt;
&lt;p&gt;
Thanks to the CB for clarifying that switch only handles ints. That issue may make my ruminations on this invalid. I dont know. Id be interested to hear from someone that does. As I said, this issue confuses me. :-)
&lt;/p&gt;
&lt;br /&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-108447"&gt;
---
&lt;br /&gt; 
demerphq&lt;br /&gt;
&lt;br /&gt;
&lt;sub&gt;

&lt;ol&gt;
&lt;p&gt;&lt;em&gt;First they ignore you, then they laugh at you, then they fight you, then you win. 
&lt;/em&gt;&lt;br /&gt; -- Gandhi&lt;/p&gt;
&lt;/ol&gt;
&lt;/sub&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;!--
&lt;hr /&gt;
&lt;sub&gt;
&lt;p&gt;
&lt;strong&gt;&amp;bull; Update:&amp;nbsp;&amp;nbsp;&lt;/strong&gt;&lt;br /&gt;

&lt;/p&gt;
&lt;/sub&gt;
--&gt;
&lt;br /&gt;
</field>
<field name="root_node">
301355</field>
<field name="parent_node">
301418</field>
</data>
</node>
