<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic In C, avoid using several nested if statements. in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/in-c-avoid-using-several-nested-if-statements/m-p/1192826#M6298</link>
    <description>&lt;P&gt;I'm considering avoiding nested if statements in my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;for (i = 0; i &amp;lt; N; i++) {
  if(x &amp;amp; y != 0) {
     if(z &amp;amp; k ==  z) {
        if(w &amp;amp; ( (c || u) &amp;amp;&amp;amp; f)) { 
            //  Do something with the checked condition
        }
      }
    }
 } 
  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The for loop, followed by many if statements, appears to be unattractive. Also, the variables x, y, z, k, and so on are of the type edgeBag. edge weight or even wider than that in width, making it look more worse.&lt;/P&gt;&lt;P&gt;One possibility is to utilize variables to store the x, y, z, and so on, and then use the variables within the if statement to check the condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt; for (i = 0; i &amp;lt; N; i++) {
 a = x;
 b = y; 
 ...
   if(a &amp;amp; b != 0) {
       ...
          ...
           // .....
    }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before posting a question here I've checked various other websites like &lt;A href="https://www.scaler.com/topics/c/nested-if-else-statement-in-c/" target="_self"&gt;Scaler&lt;/A&gt;. This did not bother me at first, but as the pattern became more frequent, it became bothersome. Is it possible to avoid this pattern? Or, to put it another way, Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2022 15:07:51 GMT</pubDate>
    <dc:creator>MubashshirHasan</dc:creator>
    <dc:date>2022-07-18T15:07:51Z</dc:date>
    <item>
      <title>In C, avoid using several nested if statements.</title>
      <link>https://community.esri.com/t5/developers-questions/in-c-avoid-using-several-nested-if-statements/m-p/1192826#M6298</link>
      <description>&lt;P&gt;I'm considering avoiding nested if statements in my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;for (i = 0; i &amp;lt; N; i++) {
  if(x &amp;amp; y != 0) {
     if(z &amp;amp; k ==  z) {
        if(w &amp;amp; ( (c || u) &amp;amp;&amp;amp; f)) { 
            //  Do something with the checked condition
        }
      }
    }
 } 
  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The for loop, followed by many if statements, appears to be unattractive. Also, the variables x, y, z, k, and so on are of the type edgeBag. edge weight or even wider than that in width, making it look more worse.&lt;/P&gt;&lt;P&gt;One possibility is to utilize variables to store the x, y, z, and so on, and then use the variables within the if statement to check the condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt; for (i = 0; i &amp;lt; N; i++) {
 a = x;
 b = y; 
 ...
   if(a &amp;amp; b != 0) {
       ...
          ...
           // .....
    }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before posting a question here I've checked various other websites like &lt;A href="https://www.scaler.com/topics/c/nested-if-else-statement-in-c/" target="_self"&gt;Scaler&lt;/A&gt;. This did not bother me at first, but as the pattern became more frequent, it became bothersome. Is it possible to avoid this pattern? Or, to put it another way, Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 15:07:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/in-c-avoid-using-several-nested-if-statements/m-p/1192826#M6298</guid>
      <dc:creator>MubashshirHasan</dc:creator>
      <dc:date>2022-07-18T15:07:51Z</dc:date>
    </item>
  </channel>
</rss>

