{"id":581,"date":"2023-02-06T18:16:21","date_gmt":"2023-02-06T18:16:21","guid":{"rendered":"https:\/\/baldsolutions.com\/?p=581"},"modified":"2023-02-06T18:16:21","modified_gmt":"2023-02-06T18:16:21","slug":"simplify-the-if-statement","status":"publish","type":"post","link":"https:\/\/baldsolutions.com\/index.php\/2023\/02\/06\/simplify-the-if-statement\/","title":{"rendered":"Simplify the &#8220;if&#8221; statement"},"content":{"rendered":"\n<p>This is probably the shortest post I&#8217;ve ever made but its content can simplify your <code>if<\/code> statements.<\/p>\n\n\n\n<p>As a developer of it is common to have  an <code>if<\/code> statement that checks if one exactly one of two conditions  is true. The first thought would be something like this: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(condition1 &amp;&amp; !condition2 || !condition1 &amp;&amp; condition2)\n   ...<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">XOR operator<\/h1>\n\n\n\n<p>There is an operator named <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/operators\/boolean-logical-operators#logical-exclusive-or-operator-\" target=\"_blank\" rel=\"noopener\" title=\"XOR\">XOR<\/a> and you probably know that.  I knew the XOR operator but didn&#8217;t use it in presented scenario. The if statement can be rewritten:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(condition1 ^ condition2)\n   ... <\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Summary<\/h1>\n\n\n\n<p>Have a nice day, bye!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is probably the shortest post I&#8217;ve ever made but its content can simplify your if statements. As a developer of it is common to&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/baldsolutions.com\/index.php\/2023\/02\/06\/simplify-the-if-statement\/\">Continue reading<span class=\"screen-reader-text\">Simplify the &#8220;if&#8221; statement<\/span><\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-net","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":11,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":592,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/posts\/581\/revisions\/592"}],"wp:attachment":[{"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/baldsolutions.com\/index.php\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}