{"id":698,"date":"2020-01-08T13:26:23","date_gmt":"2020-01-08T13:26:23","guid":{"rendered":"https:\/\/sdf-docs.mansystems.com\/docs\/acr-rules\/reliability\/chain-of-if-else-if-statements-should-have-different-conditions\/"},"modified":"2020-03-20T08:44:58","modified_gmt":"2020-03-20T08:44:58","slug":"identicalifelseifcondition","status":"publish","type":"docs","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/reliability\/identicalifelseifcondition","title":{"rendered":"Chain of &#8220;if\/else if&#8221; statements should have different conditions"},"content":{"rendered":"\n<p style=\"text-align:center\">Introduced in version: 1.3 (29 Jan 2020)<\/p>\n\n\n\n<p> A chain of if\/else if statements is evaluated from top to bottom. At most, only one branch will be executed: the first one with a condition that evaluates to true.<\/p>\n\n\n\n<p>Therefore, duplicating a condition automatically leads to dead code. Usually, this is due to a copy\/paste error. At best, it&#8217;s simply dead code and at worst, it&#8217;s a bug that will likely lead to unexpected behavior. <\/p>\n\n\n\n<p><strong>Noncompliant example:<\/strong><\/p>\n\n\n\n<p><code>if $EntityWithLongName\/VariableWithLongName = Moduleee.Enumeration.Value<strong>AA<\/strong>WithLongName then 1<br>else if $EntityWithLongName\/VariableWithLongName = Moduleee.Enumeration.Value<strong>AA<\/strong>WithLongName then 2<br>else 3<\/code><\/p>\n\n\n\n<p><strong>Compliant example:<\/strong><\/p>\n\n\n\n<p><code>if $EntityWithLongName\/VariableWithLongName = Moduleee.Enumeration.Value<strong>AA<\/strong>WithLongName then 1<br>else if $EntityWithLongName\/VariableWithLongName = Moduleee.Enumeration.Value<strong>BB<\/strong>WithLongName then 2<br>else 3 <\/code><\/p>\n","protected":false},"featured_media":0,"parent":97,"menu_order":1,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-698","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/698"}],"collection":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=698"}],"version-history":[{"count":3,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/698\/revisions"}],"predecessor-version":[{"id":1060,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/698\/revisions\/1060"}],"up":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/97"}],"next":[{"title":"Check for empty string should be done properly","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/reliability\/emptystringcheck","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/772"}],"prev":[{"title":"Attributes should not be re-assigned in create\/change object","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/reliability\/reassignedmembers","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/807"}],"wp:attachment":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=698"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}