{"id":472,"date":"2011-12-21T13:33:35","date_gmt":"2011-12-21T13:33:35","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=472"},"modified":"2011-12-21T13:36:12","modified_gmt":"2011-12-21T13:36:12","slug":"simple-boolean-operators-replace-conditional-statements","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/simple-boolean-operators-replace-conditional-statements\/","title":{"rendered":"Using simple boolean operators to replace conditional statements"},"content":{"rendered":"<p>The conditional statement (if..then.else) is Programming 101 and used in almost any useful chunk of code out there. But, they can certainly add to &quot;code-clutter&quot; when used in the most basic circumstances. Take, for example, the following logic:<\/p>\n<p><code>if item1 != &#39;&#39;:<br \/>\n\t&nbsp; print item1<br \/>\n\telif item2 != &#39;&#39;:<br \/>\n\t&nbsp; print item2<br \/>\n\telif item3 != &#39;&#39;:<br \/>\n\t&nbsp; print item3<\/code><\/p>\n<p>Pretty basic, right? The example above is written using Python syntax. Although, Python offers an exceedingly simpler approach to the exact same result:<\/p>\n<p><code>print (item1 or item2 or item3)<\/code><\/p>\n<p><em>item1<\/em> is checked for <a href=\"http:\/\/docs.python.org\/reference\/expressions.html#boolean-operations\">boolean<\/a> True, which Python defines as not <em>False<\/em>, not an <em>empty string<\/em> and not <em>None<\/em>. If it cannot reach a True value, it&#39;ll move on to <em>item2<\/em>. It&#39;s worthwhile to explore your favorite scripting languages documentation to see if a similar syntax is valid. Believe me, it&#39;s a time saver!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The conditional statement (if..then.else) is Programming 101 and used in almost any useful chunk of code out there. But, they can certainly add to &quot;code-clutter&quot;&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[97],"tags":[149],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/472"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":3,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/472\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}