c++ what does , means after ifWhat does the comma operator , do?What are the differences between a pointer variable and a reference variable in C++?What does the explicit keyword mean?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?What is the “-->” operator in C++?What is The Rule of Three?What are the basic rules and idioms for operator overloading?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why are elementwise additions much faster in separate loops than in a combined loop?Why is my program slow when looping over exactly 8192 elements?

As programers say: Strive to be lazy

How to Access data returned from Apex class in JS controller using Lightning web component

A curve pass via points at TiKz

iMac 27" 2017 memory upgrade question

Smallest Guaranteed hash collision cycle length

Find the cipher used

How can a Lich look like a human without magic?

Why do Thanos's punches not kill Captain America or at least cause some mortal injuries?

On studying Computer Science vs. Software Engineering to become a proficient coder

Was this a power play by Daenerys?

Bishop Berkeley's ideas put to the test

Does kinetic energy warp spacetime?

Why was Thor doubtful about his worthiness to Mjolnir?

How are one-time password generators like Google Authenticator different from having two passwords?

Do atomic orbitals "pulse" in time?

Does the 500 feet falling cap apply per fall, or per turn?

Why does my circuit work on a breadboard, but not on a perfboard? I am new to soldering

How to minimise the cost of guessing a number in a high/low guess game?

What is the best way for a skeleton to impersonate human without using magic?

Change FormFunction button color

Two researchers want to work on the same extension to my paper. Who to help?

What's special about a Bunsen burner?

What does "Ich wusste, dass aus dir mal was wird" mean?

How can I answer high-school writing prompts without sounding weird and fake?



c++ what does , means after if


What does the comma operator , do?What are the differences between a pointer variable and a reference variable in C++?What does the explicit keyword mean?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?What is the “-->” operator in C++?What is The Rule of Three?What are the basic rules and idioms for operator overloading?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why are elementwise additions much faster in separate loops than in a combined loop?Why is my program slow when looping over exactly 8192 elements?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








9















 for (auto i = 0; i < g.size(); ++i)
for (auto j = 0; j < g.size(); ++j) if (g[i][j] == 0) dfs(g, i, j), ++regions;
return regions;


I don't like one line code, can you please explain what does the code execute in the if() I am confused by the "," sign
usually I would write it as



 for (auto i = 0; i < g.size(); ++i)
{
for (auto j = 0; j < g.size(); ++j)

if (g[i][j] == 0)

dfs(g, i, j)

,++regions; // not sure what to do here? inside the "if" scope??

return regions;


Please help or refer me to the direction?










share|improve this question




























    9















     for (auto i = 0; i < g.size(); ++i)
    for (auto j = 0; j < g.size(); ++j) if (g[i][j] == 0) dfs(g, i, j), ++regions;
    return regions;


    I don't like one line code, can you please explain what does the code execute in the if() I am confused by the "," sign
    usually I would write it as



     for (auto i = 0; i < g.size(); ++i)
    {
    for (auto j = 0; j < g.size(); ++j)

    if (g[i][j] == 0)

    dfs(g, i, j)

    ,++regions; // not sure what to do here? inside the "if" scope??

    return regions;


    Please help or refer me to the direction?










    share|improve this question
























      9












      9








      9








       for (auto i = 0; i < g.size(); ++i)
      for (auto j = 0; j < g.size(); ++j) if (g[i][j] == 0) dfs(g, i, j), ++regions;
      return regions;


      I don't like one line code, can you please explain what does the code execute in the if() I am confused by the "," sign
      usually I would write it as



       for (auto i = 0; i < g.size(); ++i)
      {
      for (auto j = 0; j < g.size(); ++j)

      if (g[i][j] == 0)

      dfs(g, i, j)

      ,++regions; // not sure what to do here? inside the "if" scope??

      return regions;


      Please help or refer me to the direction?










      share|improve this question














       for (auto i = 0; i < g.size(); ++i)
      for (auto j = 0; j < g.size(); ++j) if (g[i][j] == 0) dfs(g, i, j), ++regions;
      return regions;


      I don't like one line code, can you please explain what does the code execute in the if() I am confused by the "," sign
      usually I would write it as



       for (auto i = 0; i < g.size(); ++i)
      {
      for (auto j = 0; j < g.size(); ++j)

      if (g[i][j] == 0)

      dfs(g, i, j)

      ,++regions; // not sure what to do here? inside the "if" scope??

      return regions;


      Please help or refer me to the direction?







      c++






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      GiladGilad

      3,46383990




      3,46383990






















          1 Answer
          1






          active

          oldest

          votes


















          12














          The programmer has used the comma operator to provide two unrelated expressions in a single statement. Because it's a single statement, both expressions are "inside" the if condition.



          It's a poor hack, which would be better done with actual braces surrounding two statements.



          Your example is not equivalent; it should be:



          if (g[i][j] == 0) 

          dfs(g, i, j);
          ++regions;






          share|improve this answer


















          • 2





            ohh god, why why why would anyone write this code. Thanks

            – Gilad
            1 hour ago






          • 2





            @Gilad Trying to be clever, most likely! And failing.

            – Lightness Races in Orbit
            1 hour ago






          • 1





            +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

            – Constantinos Glynos
            59 mins ago











          • @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

            – user4581301
            59 mins ago






          • 2





            @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

            – Andrey Sv
            49 mins ago











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56094137%2fc-what-does-means-after-if%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          12














          The programmer has used the comma operator to provide two unrelated expressions in a single statement. Because it's a single statement, both expressions are "inside" the if condition.



          It's a poor hack, which would be better done with actual braces surrounding two statements.



          Your example is not equivalent; it should be:



          if (g[i][j] == 0) 

          dfs(g, i, j);
          ++regions;






          share|improve this answer


















          • 2





            ohh god, why why why would anyone write this code. Thanks

            – Gilad
            1 hour ago






          • 2





            @Gilad Trying to be clever, most likely! And failing.

            – Lightness Races in Orbit
            1 hour ago






          • 1





            +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

            – Constantinos Glynos
            59 mins ago











          • @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

            – user4581301
            59 mins ago






          • 2





            @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

            – Andrey Sv
            49 mins ago















          12














          The programmer has used the comma operator to provide two unrelated expressions in a single statement. Because it's a single statement, both expressions are "inside" the if condition.



          It's a poor hack, which would be better done with actual braces surrounding two statements.



          Your example is not equivalent; it should be:



          if (g[i][j] == 0) 

          dfs(g, i, j);
          ++regions;






          share|improve this answer


















          • 2





            ohh god, why why why would anyone write this code. Thanks

            – Gilad
            1 hour ago






          • 2





            @Gilad Trying to be clever, most likely! And failing.

            – Lightness Races in Orbit
            1 hour ago






          • 1





            +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

            – Constantinos Glynos
            59 mins ago











          • @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

            – user4581301
            59 mins ago






          • 2





            @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

            – Andrey Sv
            49 mins ago













          12












          12








          12







          The programmer has used the comma operator to provide two unrelated expressions in a single statement. Because it's a single statement, both expressions are "inside" the if condition.



          It's a poor hack, which would be better done with actual braces surrounding two statements.



          Your example is not equivalent; it should be:



          if (g[i][j] == 0) 

          dfs(g, i, j);
          ++regions;






          share|improve this answer













          The programmer has used the comma operator to provide two unrelated expressions in a single statement. Because it's a single statement, both expressions are "inside" the if condition.



          It's a poor hack, which would be better done with actual braces surrounding two statements.



          Your example is not equivalent; it should be:



          if (g[i][j] == 0) 

          dfs(g, i, j);
          ++regions;







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          Lightness Races in OrbitLightness Races in Orbit

          298k56481827




          298k56481827







          • 2





            ohh god, why why why would anyone write this code. Thanks

            – Gilad
            1 hour ago






          • 2





            @Gilad Trying to be clever, most likely! And failing.

            – Lightness Races in Orbit
            1 hour ago






          • 1





            +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

            – Constantinos Glynos
            59 mins ago











          • @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

            – user4581301
            59 mins ago






          • 2





            @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

            – Andrey Sv
            49 mins ago












          • 2





            ohh god, why why why would anyone write this code. Thanks

            – Gilad
            1 hour ago






          • 2





            @Gilad Trying to be clever, most likely! And failing.

            – Lightness Races in Orbit
            1 hour ago






          • 1





            +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

            – Constantinos Glynos
            59 mins ago











          • @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

            – user4581301
            59 mins ago






          • 2





            @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

            – Andrey Sv
            49 mins ago







          2




          2





          ohh god, why why why would anyone write this code. Thanks

          – Gilad
          1 hour ago





          ohh god, why why why would anyone write this code. Thanks

          – Gilad
          1 hour ago




          2




          2





          @Gilad Trying to be clever, most likely! And failing.

          – Lightness Races in Orbit
          1 hour ago





          @Gilad Trying to be clever, most likely! And failing.

          – Lightness Races in Orbit
          1 hour ago




          1




          1





          +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

          – Constantinos Glynos
          59 mins ago





          +1 for the question and +1 for the answer! I didn't even know this was possible, let alone what it meant! Thanks!

          – Constantinos Glynos
          59 mins ago













          @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

          – user4581301
          59 mins ago





          @Gilad a very smart programmer once said Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. What I took from this was write the stupidest possible code that can meet the requirements. Even if I can debug sneaky code, the person I hand it off to to maintain might not.

          – user4581301
          59 mins ago




          2




          2





          @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

          – Andrey Sv
          49 mins ago





          @LightnessRacesinOrbit This is a habit of old school programmers due to small monitor resolution (25 rows 80 columns) code was writing as short as possible. More code on one page better readability. Try read modern code on such monitor and you will see how many empty rows in it.

          – Andrey Sv
          49 mins ago



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56094137%2fc-what-does-means-after-if%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown