{"id":199,"date":"2017-01-12T06:02:34","date_gmt":"2017-01-12T06:02:34","guid":{"rendered":"http:\/\/rat32.com\/rat32\/?p=199"},"modified":"2017-01-12T08:57:25","modified_gmt":"2017-01-12T08:57:25","slug":"how-to-optimize-if-else-statement-in-a-smart-way","status":"publish","type":"post","link":"https:\/\/rat32.com\/rat32\/2017\/01\/12\/how-to-optimize-if-else-statement-in-a-smart-way\/","title":{"rendered":"How to optimize if else statement in a smart way?"},"content":{"rendered":"<p>In this tutorial i am going to show how can we optimize the if else statement. This method can be used in any programming languages. I am going to show two different ways we can optimize the if else statement.<\/p>\n<p>lets see default if else statement:<\/p>\n<p>if( n % 2 == 0){<br \/>\n    result = n + &#8221; is even number&#8221;;<br \/>\n}else{<br \/>\n    result = n + &#8221; is odd number&#8221;;<br \/>\n}<br \/>\nprint result;<\/p>\n<p>Method 1:<br \/>\nresult = n + &#8221; is odd number&#8221;;<br \/>\nif( n % 2 == 0){<br \/>\n    result = n + &#8221; is even number&#8221;;<br \/>\n}<br \/>\nprint result;<\/p>\n<p>In this first method we define result variable as odd number and then use only if statement to alter the result if it is not an odd number. This is a first smart way.<\/p>\n<p>Method 2:<br \/>\nresult = ( n % 2 == 0)?n + &#8221; is even number&#8221;:n + &#8221; is odd number&#8221;;<br \/>\nprint result;<\/p>\n<p>This second method is a use of ternary operator. The syntax of ternary operator is conditionCheck?trueStatement:falseStatement. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In this tutorial i am going to show how can we optimize the if else statement. This method can be used in any programming languages. I am going to show two different ways we&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-how-to"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts\/199"}],"collection":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/comments?post=199"}],"version-history":[{"count":2,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":201,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts\/199\/revisions\/201"}],"wp:attachment":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}