<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A neat way to express multi-clause if statements in C-based languages</title>
	<atom:link href="http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/feed/" rel="self" type="application/rss+xml" />
	<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/</link>
	<description>On programming, technology, and random things of interest</description>
	<lastBuildDate>Thu, 29 Jul 2010 00:28:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Fabiano PS</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-776</link>
		<dc:creator>Fabiano PS</dc:creator>
		<pubDate>Wed, 24 Feb 2010 14:31:21 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-776</guid>
		<description>Sorry, missed the code tag.. again the switch from ruby:

&lt;code&gt;
case(true)
when 1&gt;2
  p 1
when 1&lt;2
  p 2
end
#= 2
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Sorry, missed the code tag.. again the switch from ruby:</p>
<p><code><br />
case(true)<br />
when 1&gt;2<br />
  p 1<br />
when 1&lt;2<br />
  p 2<br />
end<br />
#= 2<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabiano PS</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-775</link>
		<dc:creator>Fabiano PS</dc:creator>
		<pubDate>Wed, 24 Feb 2010 14:29:22 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-775</guid>
		<description>Awesome! As a ruby programmer loved the entire post

Just tested Ruby&#039;s (v1.8) case-when and works the same:

case(true)
when 1&gt;2
  p 1
when 1 2</description>
		<content:encoded><![CDATA[<p>Awesome! As a ruby programmer loved the entire post</p>
<p>Just tested Ruby&#8217;s (v1.8) case-when and works the same:</p>
<p>case(true)<br />
when 1&gt;2<br />
  p 1<br />
when 1 2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: No One</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-670</link>
		<dc:creator>No One</dc:creator>
		<pubDate>Tue, 02 Feb 2010 17:57:12 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-670</guid>
		<description>(there was specific indentation there that made it much more readable, which the &quot;code&quot; tag did not preserve)</description>
		<content:encoded><![CDATA[<p>(there was specific indentation there that made it much more readable, which the &#8220;code&#8221; tag did not preserve)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: No One</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-669</link>
		<dc:creator>No One</dc:creator>
		<pubDate>Tue, 02 Feb 2010 17:56:20 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-669</guid>
		<description>This form actually appears in K&amp;R&#039;s original C Programming language book, except they put the colon at the _end_ of the previous line, e.g.

&lt;code&gt;
const char *number = 
   i  &lt; 0 ? &quot;negative&quot; :
   i == 0 ? &quot;zero&quot;     :
   i == 1 ? &quot;one&quot;      :
   i == 2 ? &quot;two&quot;      :
            &quot;lots!&quot;    ;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>This form actually appears in K&amp;R&#8217;s original C Programming language book, except they put the colon at the _end_ of the previous line, e.g.</p>
<p><code><br />
const char *number =<br />
   i  &lt; 0 ? &quot;negative&quot; :<br />
   i == 0 ? &quot;zero&quot;     :<br />
   i == 1 ? &quot;one&quot;      :<br />
   i == 2 ? &quot;two&quot;      :<br />
            &quot;lots!&quot;    ;<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-574</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Wed, 09 Sep 2009 20:45:55 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-574</guid>
		<description>Thanks for coming back to clear it up, Harris. :-)

It is also possible that some C++ compilers accept and some reject that pattern. So perhaps you really did write that code in the past.</description>
		<content:encoded><![CDATA[<p>Thanks for coming back to clear it up, Harris. <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>It is also possible that some C++ compilers accept and some reject that pattern. So perhaps you really did write that code in the past.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harris Bhatti</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-573</link>
		<dc:creator>Harris Bhatti</dc:creator>
		<pubDate>Wed, 09 Sep 2009 20:15:43 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-573</guid>
		<description>Finally!

I remember i posted the quote somewhere couldn&#039;t get back to the website. CORRECTION IS IN ORDER: the sample code in my previous comment is not valid c++ contrary to my beliefs before. I was pretty sure I had used that somewhere before but obviously not as i tried using the syntax above again and well the compiler denied me a twinkie. Igor, I would appreciate it if you could delete my comment and spare some sane people from some misleading remarks and conjured up syntax :). Thank You.</description>
		<content:encoded><![CDATA[<p>Finally!</p>
<p>I remember i posted the quote somewhere couldn&#8217;t get back to the website. CORRECTION IS IN ORDER: the sample code in my previous comment is not valid c++ contrary to my beliefs before. I was pretty sure I had used that somewhere before but obviously not as i tried using the syntax above again and well the compiler denied me a twinkie. Igor, I would appreciate it if you could delete my comment and spare some sane people from some misleading remarks and conjured up syntax <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Thank You.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-438</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Tue, 13 Jan 2009 21:26:04 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-438</guid>
		<description>Harris,

I agree that formatting is very important for this particular pattern.

Crazy what you can do with C++... Pretty cool. C# actually requires the clauses to be expressions, so you cannot use statements like &quot;return 1&quot;. I would expect Java to behave similarly.

Igor</description>
		<content:encoded><![CDATA[<p>Harris,</p>
<p>I agree that formatting is very important for this particular pattern.</p>
<p>Crazy what you can do with C++&#8230; Pretty cool. C# actually requires the clauses to be expressions, so you cannot use statements like &#8220;return 1&#8243;. I would expect Java to behave similarly.</p>
<p>Igor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harris Bhatti</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-437</link>
		<dc:creator>Harris Bhatti</dc:creator>
		<pubDate>Tue, 13 Jan 2009 14:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-437</guid>
		<description>Clean is a relative term. :). It all boils down to the formatting really. if i were to reformat the code into something else it wouldn&#039;t look that clean on the other hand if/elseif depending upon the formatting can be written in clean ways.

&lt;strong&gt;[Admin note:  Harris later &lt;a href=&quot;http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-573&quot; rel=&quot;nofollow&quot;&gt;corrected&lt;/a&gt; the following part of the comment]&lt;/strong&gt;

Also note that it is not necessary for a ternary statement to assign something.
You could always do:

(condition1) ? resultvar = resultval : ( (condition2) ? return 1 : default;

So you can see using it that way gives you other possibilities as well and you could take the program flow in which ever direction you want instead of having to return something for each branch.</description>
		<content:encoded><![CDATA[<p>Clean is a relative term. <img src='http://igoro.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . It all boils down to the formatting really. if i were to reformat the code into something else it wouldn&#8217;t look that clean on the other hand if/elseif depending upon the formatting can be written in clean ways.</p>
<p><strong>[Admin note:  Harris later <a href="http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-573" rel="nofollow">corrected</a> the following part of the comment]</strong></p>
<p>Also note that it is not necessary for a ternary statement to assign something.<br />
You could always do:</p>
<p>(condition1) ? resultvar = resultval : ( (condition2) ? return 1 : default;</p>
<p>So you can see using it that way gives you other possibilities as well and you could take the program flow in which ever direction you want instead of having to return something for each branch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hugh Brown</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-289</link>
		<dc:creator>Hugh Brown</dc:creator>
		<pubDate>Thu, 05 Jun 2008 19:15:51 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-289</guid>
		<description>Do I have to escape my code as HTML? Okay.

Maybe this:

string commentCount =
    string.Format(&quot;{0} comment%s&quot;, 
    (n == 0 ? &quot;no&quot;
    : n &lt; 100 ? n.ToString()
    : &quot;100+&quot;),
    (n == 1 ? &quot;&quot; : &quot;s&quot;);

or this:

string commentCount =
    (n == 0 ? &quot;no&quot;
    : n &lt; 100 ? n.ToString()
    : &quot;100+&quot;) +
    &quot; comment&quot; +
    (n == 1 ? &quot;&quot; : &quot;s&quot;);</description>
		<content:encoded><![CDATA[<p>Do I have to escape my code as HTML? Okay.</p>
<p>Maybe this:</p>
<p>string commentCount =<br />
    string.Format(&#8220;{0} comment%s&#8221;,<br />
    (n == 0 ? &#8220;no&#8221;<br />
    : n &lt; 100 ? n.ToString()<br />
    : &#8220;100+&#8221;),<br />
    (n == 1 ? &#8220;&#8221; : &#8220;s&#8221;);</p>
<p>or this:</p>
<p>string commentCount =<br />
    (n == 0 ? &#8220;no&#8221;<br />
    : n &lt; 100 ? n.ToString()<br />
    : &#8220;100+&#8221;) +<br />
    &#8221; comment&#8221; +<br />
    (n == 1 ? &#8220;&#8221; : &#8220;s&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hugh Brown</title>
		<link>http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/comment-page-1/#comment-288</link>
		<dc:creator>Hugh Brown</dc:creator>
		<pubDate>Thu, 05 Jun 2008 19:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/a-neat-way-to-express-multi-clause-if-statements-in-c-based-languages/#comment-288</guid>
		<description>Or maybe:

string commentCount =
    string.Format(&quot;{0} comment{1}&quot;, 
        (n == 0 ? &quot;no&quot;
        : n </description>
		<content:encoded><![CDATA[<p>Or maybe:</p>
<p>string commentCount =<br />
    string.Format(&#8220;{0} comment{1}&#8221;,<br />
        (n == 0 ? &#8220;no&#8221;<br />
        : n</p>
]]></content:encoded>
	</item>
</channel>
</rss>
