<?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: Switch vs. If</title>
	<atom:link href="http://sun3.org/archives/88/feed" rel="self" type="application/rss+xml" />
	<link>http://sun3.org/archives/88</link>
	<description>Rob Thompson&#039;s Blog</description>
	<lastBuildDate>Sat, 31 Dec 2011 12:42:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Jamie</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-340</link>
		<dc:creator>Jamie</dc:creator>
		<pubDate>Tue, 16 Nov 2010 21:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-340</guid>
		<description>@Patryk - that may work, but man is it ugly and counter-intuitive.</description>
		<content:encoded><![CDATA[<p>@Patryk &#8211; that may work, but man is it ugly and counter-intuitive.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patryk Januszewski</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-339</link>
		<dc:creator>Patryk Januszewski</dc:creator>
		<pubDate>Mon, 08 Nov 2010 18:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-339</guid>
		<description>I noticed that you mentioned at the end of your post that the switch is great for value matching, but I&#039;ve also used it for more complex logical matches as well (since everything really just get processed down to a value. I&#039;ve done the following to replace an if-else-if :

switch (true) {
    case isset($donkey[&#039;face&#039;]):
        ...
        break;
    case isset($donkey[&#039;pants&#039;]):
        ...
        break;
    case isset($donkey[&#039;butt&#039;]):
        ...
        break;
}

Just sharing :)</description>
		<content:encoded><![CDATA[<p>I noticed that you mentioned at the end of your post that the switch is great for value matching, but I&#8217;ve also used it for more complex logical matches as well (since everything really just get processed down to a value. I&#8217;ve done the following to replace an if-else-if :</p>
<p>switch (true) {<br />
    case isset($donkey['face']):<br />
        &#8230;<br />
        break;<br />
    case isset($donkey['pants']):<br />
        &#8230;<br />
        break;<br />
    case isset($donkey['butt']):<br />
        &#8230;<br />
        break;<br />
}</p>
<p>Just sharing :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: doro</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-327</link>
		<dc:creator>doro</dc:creator>
		<pubDate>Tue, 29 Jun 2010 09:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-327</guid>
		<description>i was wondering about the same thing, for some reason lately i like using switch more.. good to see that there&#039;s no speed problem :)</description>
		<content:encoded><![CDATA[<p>i was wondering about the same thing, for some reason lately i like using switch more.. good to see that there&#8217;s no speed problem :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-319</link>
		<dc:creator>Justin</dc:creator>
		<pubDate>Fri, 07 May 2010 00:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-319</guid>
		<description>Frankly, I couldn&#039;t care less that the switch statement is X milliseconds faster or slower in Y fringe scenarios.

If you&#039;re replacing your if statements with switch statements and each case has a break after it, you&#039;re misusing the language&#039;s features.

In my code, scenarios where switch is the right tool for the job are extremely rare and, when I find myself in such a position, I often ask myself if there&#039;s a better way to do what I&#039;m trying.

This vaguely reminds me of explaining to someone why you don&#039;t use the bold tag in markup, you use the strong tag.

This is all completely beside preference.  I have no idea how anyone could find a switch statement prettier than an if/else.  PHP has C-style brackets for a reason.</description>
		<content:encoded><![CDATA[<p>Frankly, I couldn&#8217;t care less that the switch statement is X milliseconds faster or slower in Y fringe scenarios.</p>
<p>If you&#8217;re replacing your if statements with switch statements and each case has a break after it, you&#8217;re misusing the language&#8217;s features.</p>
<p>In my code, scenarios where switch is the right tool for the job are extremely rare and, when I find myself in such a position, I often ask myself if there&#8217;s a better way to do what I&#8217;m trying.</p>
<p>This vaguely reminds me of explaining to someone why you don&#8217;t use the bold tag in markup, you use the strong tag.</p>
<p>This is all completely beside preference.  I have no idea how anyone could find a switch statement prettier than an if/else.  PHP has C-style brackets for a reason.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-317</link>
		<dc:creator>Thomas</dc:creator>
		<pubDate>Thu, 29 Apr 2010 11:12:08 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-317</guid>
		<description>Hmm, what was the setup (os, php v, etc), one wonders. Tested 100,000,000 iterations with php 5.3.2 on windows+freebsd+ubuntu server (both scripts noticeably slower in windows - surprise!). Very little difference. Have they changed if vs switch behavior perhaps? @pj: I&#039;d guess yes. Do the same. Easier to read and make changes (debugging e.g.)</description>
		<content:encoded><![CDATA[<p>Hmm, what was the setup (os, php v, etc), one wonders. Tested 100,000,000 iterations with php 5.3.2 on windows+freebsd+ubuntu server (both scripts noticeably slower in windows &#8211; surprise!). Very little difference. Have they changed if vs switch behavior perhaps? @pj: I&#8217;d guess yes. Do the same. Easier to read and make changes (debugging e.g.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andre.roesti</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-315</link>
		<dc:creator>andre.roesti</dc:creator>
		<pubDate>Thu, 25 Feb 2010 20:28:29 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-315</guid>
		<description>Every Millisecond counts. Thanks for sharing it.</description>
		<content:encoded><![CDATA[<p>Every Millisecond counts. Thanks for sharing it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pj</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-314</link>
		<dc:creator>pj</dc:creator>
		<pubDate>Thu, 25 Feb 2010 17:34:27 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-314</guid>
		<description>Thanks a lot! I got to the &quot;PHP Switch&quot; chapter of PHP Basic course at W3Schools.com and immediately wondered about (and googled)  the difference between if vs switch. Thanks to you I learned when to use each one!

Also, beginner question: I see you use curly braces { and } even when you only have 1 line to be executed for a certain if or elseif statement. I assume you do this just out of habit?</description>
		<content:encoded><![CDATA[<p>Thanks a lot! I got to the &#8220;PHP Switch&#8221; chapter of PHP Basic course at W3Schools.com and immediately wondered about (and googled)  the difference between if vs switch. Thanks to you I learned when to use each one!</p>
<p>Also, beginner question: I see you use curly braces { and } even when you only have 1 line to be executed for a certain if or elseif statement. I assume you do this just out of habit?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://sun3.org/archives/88/comment-page-1#comment-312</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 19 Feb 2010 20:13:19 +0000</pubDate>
		<guid isPermaLink="false">http://sun3.org/?p=88#comment-312</guid>
		<description>Thanks for this! Was just wondering about the same thing.</description>
		<content:encoded><![CDATA[<p>Thanks for this! Was just wondering about the same thing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

