<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[The Osmosian Order of Plain English Programmers Welcomes You]]></provider_name><provider_url><![CDATA[http://osmosianplainenglishprogramming.blog]]></provider_url><author_name><![CDATA[gerryrzeppa]]></author_name><author_url><![CDATA[https://osmosianplainenglishprogramming.blog/author/gerryrzeppa/]]></author_url><title><![CDATA[Plain English Programming — Nested&nbsp;IFs]]></title><type><![CDATA[link]]></type><html><![CDATA[<header class="entry-header">
<h1 class="entry-title"></h1>
</header>
<div class="entry-content">
<p>This is a picture of Sharon, the Mother of all Osmosians:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-317034" src="https://cdncontribute.geeksforgeeks.org/wp-content/uploads/osmosian-mom-1.png" alt="" width="384" height="288" /></p>
<p>Her favorite saying is, “Just tell us what you need, sonny, and we’ll show you how to live without it.” She insisted, in fact, that we use nothing but black dots of different sizes to show you what she looks like.</p>
<p>Another of her favorite sayings is about nested IFs. She says, “Two deep is too deep, boys. No nesting.”</p>
<p>Now everyone knows that “If Momma ain’t happy, ain’t nobody happy,” so when we developed our Plain English compiler we intentionally left out nested IFs. Turns out she was right, as usual — they’re not necessary. Search through the 25,000 Plain English sentences that comprise our system — unique desktop, simplified file manager, elegant text editor, handy hexadecimal dumper, native-code-generating compiler/linker, and WYSIWYG document editor — and you won’t find a single nested IF. Nada. Zip. Zilch. No “elses” either.</p>
<p><strong>An Example</strong></p>
<p>So how does one live without nested IFs? Let’s consider an example given by R S Abhishek, a Research Associate at Ati Motors that popped up when I asked Google for a “real life nested IF statement”:</p>
<p>&nbsp;</p>
<div>
<div id="highlighter_493377" class="syntaxhighlighter  cpp">
<table style="height:621px;" border="0" width="678" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="cpp keyword bold">if</code><code class="cpp plain">(age &lt; 60){</code></div>
<div class="line number2 index1 alt1"><code class="cpp spaces">    </code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &lt;= 250000){</code></div>
<div class="line number3 index2 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0 </code></div>
<div class="line number4 index3 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &gt;= 250001 &amp;&amp; income &lt;= 500000){</code></div>
<div class="line number5 index4 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.1</code></div>
<div class="line number6 index5 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &gt;= 500001 &amp;&amp; income &lt;= 1000000){</code></div>
<div class="line number7 index6 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.2</code></div>
<div class="line number8 index7 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp plain">{</code></div>
<div class="line number9 index8 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.3</code></div>
<div class="line number10 index9 alt1"><code class="cpp spaces">    </code><code class="cpp plain">} </code></div>
<div class="line number11 index10 alt2"><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp keyword bold">if</code><code class="cpp plain">(age &gt;= 60 &amp;&amp; age &lt; 80){</code></div>
<div class="line number12 index11 alt1"><code class="cpp spaces">    </code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &lt;= 300000){</code></div>
<div class="line number13 index12 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0</code></div>
<div class="line number14 index13 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &gt;= 300001 &amp;&amp; income &lt;= 500000){</code></div>
<div class="line number15 index14 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.1</code></div>
<div class="line number16 index15 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &gt;= 500001 &amp;&amp; income &lt;= 1000000){</code></div>
<div class="line number17 index16 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.2</code></div>
<div class="line number18 index17 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp plain">{</code></div>
<div class="line number19 index18 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.3</code></div>
<div class="line number20 index19 alt1"><code class="cpp spaces">    </code><code class="cpp plain">} </code></div>
<div class="line number21 index20 alt2"><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp plain">{</code></div>
<div class="line number22 index21 alt1"><code class="cpp spaces">    </code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &lt;= 500000){</code></div>
<div class="line number23 index22 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0</code></div>
<div class="line number24 index23 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp keyword bold">if</code><code class="cpp plain">(income &gt;= 500001 &amp;&amp; income &lt;= 1000000){</code></div>
<div class="line number25 index24 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.2</code></div>
<div class="line number26 index25 alt1"><code class="cpp spaces">    </code><code class="cpp plain">}</code><code class="cpp keyword bold">else</code><code class="cpp plain">{</code></div>
<div class="line number27 index26 alt2"><code class="cpp spaces">        </code><code class="cpp plain">tax_percent = 0.3</code></div>
</div>
</td>
</tr>
</tbody>
</table>
<p>Twenty-seven lines there, with lots of indention, highlighted keywords, and too many squiggly braces for me to count. Now Let’s consider the non-nested, Plain English equivalent:</p>
<p><span style="color:#00ccff;">To get a tax rate for an age and an income:<br />
</span><span style="color:#00ccff;">If the age is less than 60, get the tax rate for young people with the income; exit.<br />
</span><span style="color:#00ccff;">If the age is between 60 and 79, get the tax rate for old folks with the income; exit.<br />
</span><span style="color:#00ccff;">If the income is less than or equal to 500000, put 0 into the tax rate, exit.<br />
</span><span style="color:#00ccff;">If the income is between 500001 and 500000, put 2/1000 into the tax rate; exit.<br />
</span><span style="color:#00ccff;">Put 3/1000 into the tax rate.</p>
<p></span></p>
</div>
</div>
<p><span style="color:#00ccff;">To get a tax rate for young people given an income:</span><br />
<span style="color:#00ccff;"> If the income is less than or equal to 250000, put 0 into the tax rate, exit.</span><br />
<span style="color:#00ccff;"> If the income is between 250001 and 500000, put 1/1000 into the tax rate; exit.</span><br />
<span style="color:#00ccff;"> If the income is between 500001 and 1000000, put 2/1000 into the tax rate; exit.</span><br />
<span style="color:#00ccff;"> Put 3/1000 into the tax rate.</span></p>
<p><span style="color:#00ccff;">To get a tax rate for old folks given an income:</span><br />
<span style="color:#00ccff;"> If the income is less than or equal to 300000, put 0 into the tax rate, exit.</span><br />
<span style="color:#00ccff;"> If the income is between 300001 and 500000, put 1/1000 into the tax rate; exit.</span><br />
<span style="color:#00ccff;"> If the income is between 500001 and 1000000, put 2/1000 into the tax rate; exit.</span><br />
<span style="color:#00ccff;"> Put 3/1000 into the tax rate.</span></p>
<p>Just eighteen lines (including the optional blanks between the routines), and a mere handful of punctuation marks — all used in the usual ways.</p>
<p>The trick, you see, is to properly factor the problem by handling (and thus eliminating) special cases at the top, exiting after each. The normal/default/fall-through case then appears, unconditioned, at the bottom.</p>
<p><strong>Some notes</strong></p>
<p>If you’re wondering whether “between” in Plain English is inclusive or exclusive, just do what we did. Head down to the local Walmart and ask the folks coming and going to “Pick a number between 1 and 10.” You’ll find that lots of people choose 1 and 10, which shows that the <em>normal </em>interpretation of “between” is inclusive.</p>
<p>And if you’re wondering why we put “3/1000” into the tax rate (instead of 0.3, like the other guy), it’s because Plain English is a whole-number only language. Why? Because our Osmosian Mom used to put us to sleep with stories from an ancient Osmosian adventure book entitled, <em>The Epic Battle for the Soul of Mathematics: Kronecker vs Cantor.</em> I remember, in fact, this painting hanging over my bed:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-316976" src="https://cdncontribute.geeksforgeeks.org/wp-content/uploads/kronecker-3-scan-small.jpg" alt="" width="432" height="336" /></p>
<p>But that’s really a whole ‘nother story. It will have to wait for another article. Suffice it to say, at this juncture, that Mom was right about nested IFs — you don’t need ’em.</p>
</div>
]]></html><thumbnail_url><![CDATA[https://i2.wp.com/cdncontribute.geeksforgeeks.org/wp-content/uploads/osmosian-mom-1.png?fit=440%2C330&ssl=1]]></thumbnail_url><thumbnail_width><![CDATA[384]]></thumbnail_width><thumbnail_height><![CDATA[288]]></thumbnail_height></oembed>