<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Reference Book Blog &#187; else</title>
	<atom:link href="http://www.phpreferencebook.com/tag/else/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpreferencebook.com</link>
	<description>PHP Reference: Beginner to Intermediate PHP5</description>
	<lastBuildDate>Wed, 25 Aug 2010 12:58:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Control Structures Without Curly Braces</title>
		<link>http://www.phpreferencebook.com/clarifications/control-structures-curly-braces/</link>
		<comments>http://www.phpreferencebook.com/clarifications/control-structures-curly-braces/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 17:00:53 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Clarifications]]></category>
		<category><![CDATA[control structures]]></category>
		<category><![CDATA[do-while]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[elseif]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[while]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=44</guid>
		<description><![CDATA[In the book I cover the standard syntax methods for if, elseif, else, while, do-while, switch, for, and foreach. Here is the if statement syntax: if &#40;expr&#41; &#123; // If expr is TRUE,  do this, then exit the IF loop &#125;elseif &#40;expr2&#41; &#123; // If expr is FALSE, and expr2 is TRUE, do this, then [...]]]></description>
			<content:encoded><![CDATA[<p>In the book I cover the standard syntax methods for if, elseif, else, while, do-while, switch, for, and foreach. Here is the if statement syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>expr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// If expr is TRUE,  do this, then exit the IF loop</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>expr2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// If expr is FALSE, and expr2 is TRUE, do this, then exit the loop</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// If all expr's are FALSE, do this, then exit</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>While accurate, there is a shorthand method that does not involve the curly bracket. If there is only a single evaluation, you can remove the curly braces completely. The following two examples are both completely valid syntax for control structures:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, I still recommend using curly brackets, if only for clarity and consistency (excluding them for the second line above would make your life much harder than necessary, but I thought a clarification was in order. For more information on Control Structions, check out chapter 3, pages 25-32 of the <a href="http://www.phpreferencebook.com/pdf/">free PHP book PDF</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/clarifications/control-structures-curly-braces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
