What does a comma mean inside an 'if' statement? [duplicate]What does the comma operator , do?comma operator in if conditionWhat is the difference between #include <filename> and #include “filename”?What are the differences between a pointer variable and a reference variable in C++?What does the explicit keyword mean?What is the “-->” operator in C++?What is The Rule of Three?What is the meaning of prepended double colon “::”?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?

Rushed passport - does my reason qualify?

Why does the U.S military use mercenaries?

Would a "ring language" be possible?

How to generate a triangular grid from a list of points

Polynomial division: Is this trick obvious?

What are the effects of eating many berries from the Goodberry spell per day?

Does a non-singular matrix have a large minor with disjoint rows and columns and full rank?

Assign the same string to multiple variables

Usage of the relative pronoun "dont"

Why is Drogon so much better in battle than Rhaegal and Viserion?

Square spiral in Mathematica

301 Redirects what does ([a-z]+)-(.*) and ([0-9]+)-(.*) mean

How come Arya Stark didn't burn in Game of Thrones Season 8 Episode 5

Why do galaxies collide?

Cannot remove door knob -- totally inaccessible!

Failing students when it might cause them economic ruin

Divisor Rich and Poor Numbers

What is the velocity distribution of the exhaust for a typical rocket engine?

Why is so much ransomware breakable?

Is Precocious Apprentice enough for Mystic Theurge?

Is there an academic word that means "to split hairs over"?

FIFO data structure in pure C

How was the blinking terminal cursor invented?

"Counterexample" for the Inverse function theorem



What does a comma mean inside an 'if' statement? [duplicate]


What does the comma operator , do?comma operator in if conditionWhat is the difference between #include <filename> and #include “filename”?What are the differences between a pointer variable and a reference variable in C++?What does the explicit keyword mean?What is the “-->” operator in C++?What is The Rule of Three?What is the meaning of prepended double colon “::”?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;








19
















This question already has an answer here:



  • What does the comma operator , do?

    9 answers



Consider:



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. 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; // I am not sure what to do here. Inside the "if" scope??


return regions;









share|improve this question















marked as duplicate by phuclv, David Z, Community May 12 at 4:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    The second code snippet is not balanced - there are three opening s and two closing s - it is missing a }.

    – Peter Mortensen
    May 11 at 22:53












  • See also here: stackoverflow.com/questions/16475032/…

    – Valentino
    May 11 at 23:07

















19
















This question already has an answer here:



  • What does the comma operator , do?

    9 answers



Consider:



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. 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; // I am not sure what to do here. Inside the "if" scope??


return regions;









share|improve this question















marked as duplicate by phuclv, David Z, Community May 12 at 4:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    The second code snippet is not balanced - there are three opening s and two closing s - it is missing a }.

    – Peter Mortensen
    May 11 at 22:53












  • See also here: stackoverflow.com/questions/16475032/…

    – Valentino
    May 11 at 23:07













19












19








19









This question already has an answer here:



  • What does the comma operator , do?

    9 answers



Consider:



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. 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; // I am not sure what to do here. Inside the "if" scope??


return regions;









share|improve this question

















This question already has an answer here:



  • What does the comma operator , do?

    9 answers



Consider:



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. 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; // I am not sure what to do here. Inside the "if" scope??


return regions;




This question already has an answer here:



  • What does the comma operator , do?

    9 answers







c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







Gilad

















asked May 11 at 20:44









GiladGilad

3,51383992




3,51383992




marked as duplicate by phuclv, David Z, Community May 12 at 4:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by phuclv, David Z, Community May 12 at 4:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    The second code snippet is not balanced - there are three opening s and two closing s - it is missing a }.

    – Peter Mortensen
    May 11 at 22:53












  • See also here: stackoverflow.com/questions/16475032/…

    – Valentino
    May 11 at 23:07












  • 1





    The second code snippet is not balanced - there are three opening s and two closing s - it is missing a }.

    – Peter Mortensen
    May 11 at 22:53












  • See also here: stackoverflow.com/questions/16475032/…

    – Valentino
    May 11 at 23:07







1




1





The second code snippet is not balanced - there are three opening s and two closing s - it is missing a }.

– Peter Mortensen
May 11 at 22:53






The second code snippet is not balanced - there are three opening s and two closing s - it is missing a }.

– Peter Mortensen
May 11 at 22:53














See also here: stackoverflow.com/questions/16475032/…

– Valentino
May 11 at 23:07





See also here: stackoverflow.com/questions/16475032/…

– Valentino
May 11 at 23:07












1 Answer
1






active

oldest

votes


















27














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


















  • 7





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

    – Gilad
    May 11 at 20:50






  • 8





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

    – Lightness Races in Orbit
    May 11 at 20:51






  • 4





    @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
    May 11 at 21:14






  • 3





    Of course, that hack is especially useful for macros, which one also should avoid assiduously.

    – Deduplicator
    May 11 at 21:33






  • 3





    @AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

    – Lightness Races in Orbit
    May 11 at 22:59

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









27














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


















  • 7





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

    – Gilad
    May 11 at 20:50






  • 8





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

    – Lightness Races in Orbit
    May 11 at 20:51






  • 4





    @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
    May 11 at 21:14






  • 3





    Of course, that hack is especially useful for macros, which one also should avoid assiduously.

    – Deduplicator
    May 11 at 21:33






  • 3





    @AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

    – Lightness Races in Orbit
    May 11 at 22:59















27














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


















  • 7





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

    – Gilad
    May 11 at 20:50






  • 8





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

    – Lightness Races in Orbit
    May 11 at 20:51






  • 4





    @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
    May 11 at 21:14






  • 3





    Of course, that hack is especially useful for macros, which one also should avoid assiduously.

    – Deduplicator
    May 11 at 21:33






  • 3





    @AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

    – Lightness Races in Orbit
    May 11 at 22:59













27












27








27







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 May 11 at 20:46









Lightness Races in OrbitLightness Races in Orbit

299k56484831




299k56484831







  • 7





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

    – Gilad
    May 11 at 20:50






  • 8





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

    – Lightness Races in Orbit
    May 11 at 20:51






  • 4





    @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
    May 11 at 21:14






  • 3





    Of course, that hack is especially useful for macros, which one also should avoid assiduously.

    – Deduplicator
    May 11 at 21:33






  • 3





    @AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

    – Lightness Races in Orbit
    May 11 at 22:59












  • 7





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

    – Gilad
    May 11 at 20:50






  • 8





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

    – Lightness Races in Orbit
    May 11 at 20:51






  • 4





    @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
    May 11 at 21:14






  • 3





    Of course, that hack is especially useful for macros, which one also should avoid assiduously.

    – Deduplicator
    May 11 at 21:33






  • 3





    @AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

    – Lightness Races in Orbit
    May 11 at 22:59







7




7





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

– Gilad
May 11 at 20:50





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

– Gilad
May 11 at 20:50




8




8





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

– Lightness Races in Orbit
May 11 at 20:51





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

– Lightness Races in Orbit
May 11 at 20:51




4




4





@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
May 11 at 21:14





@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
May 11 at 21:14




3




3





Of course, that hack is especially useful for macros, which one also should avoid assiduously.

– Deduplicator
May 11 at 21:33





Of course, that hack is especially useful for macros, which one also should avoid assiduously.

– Deduplicator
May 11 at 21:33




3




3





@AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

– Lightness Races in Orbit
May 11 at 22:59





@AndreySv Such programmers have had some thirty years to break that habit, i.e. since before C++ even existed.

– Lightness Races in Orbit
May 11 at 22:59





Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form