What does a comma mean inside an 'if' statement?What does the comma operator , do?comma operator in if conditionWhat 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 copy-and-swap idiom?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?
Run script for 10 times until meets the condition, but break the loop if it meets the condition during iteration
Why is this int array not passed as an object vararg array?
Why does getw return -1 when trying to read a character?
Find the cipher used
What does a comma mean inside an 'if' statement?
Why do Thanos's punches not kill Captain America or at least cause some mortal injuries?
Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?
Ex-manager wants to stay in touch, I don't want to
How can a Lich look like a human without magic?
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
What is the best way for a skeleton to impersonate human without using magic?
On studying Computer Science vs. Software Engineering to become a proficient coder
Extrude the faces of a cube symmetrically along XYZ
What is Plautus’s pun about frustum and frustrum?
How can this triangle figure be modeled/drawn with TikZ?
On what legal basis did the UK remove the 'European Union' from its passport?
Is it a bad idea to replace pull-up resistors with hard pull-ups?
How does Howard Stark know this?
What's the word for the soldier salute?
Size of a folder with du
Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?
Does the 500 feet falling cap apply per fall, or per turn?
Is the schwa sound consistent?
Can I use my laptop, which says 100-240V, in the USA?
What does a comma mean inside an 'if' statement?
What does the comma operator , do?comma operator in if conditionWhat 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 copy-and-swap idiom?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;
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)
improve this question
add a comment |
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)
improve this question
The second code snippet is not balanced - there are three openings and two closing
s - it is missing a
.
– Peter Mortensen
55 mins ago
See also here: stackoverflow.com/questions/16475032/…
– Valentino
41 mins ago
add a comment |
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)
improve this question
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)
improve this question
See also here: stackoverflow.com/questions/16475032/…
– Valentino
41 mins ago
add a comment .
– Peter Mortensen
55 mins ago
See also here: stackoverflow.com/questions/16475032/…
– Valentino
41 mins ago
The second code snippet is not balanced - there are three opening
s and two closing
s - it is missing a }
.– Peter Mortensen
55 mins ago
The second code snippet is not balanced - there are three opening
s and two closing
s - it is missing a }
.– Peter Mortensen
55 mins ago
See also here: stackoverflow.com/questions/16475032/…
– Valentino
41 mins ago
See also here: stackoverflow.com/questions/16475032/…
– Valentino
41 mins ago
add a comment |
1 Answer
1
active
oldest
votes
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;
3
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
3
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
2
+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
2 hours ago
3
@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
2 hours ago
2
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
|
show 12 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56094137%2fwhat-does-a-comma-mean-inside-an-if-statement%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
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;
3
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
3
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
2
+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
2 hours ago
3
@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
2 hours ago
2
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
|
show 12 more comments
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;
3
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
3
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
2
+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
2 hours ago
3
@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
2 hours ago
2
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
|
show 12 more comments
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;
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;
answered 3 hours ago
Lightness Races in OrbitLightness Races in Orbit
298k56482828
298k56482828
3
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
3
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
2
+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
2 hours ago
3
@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
2 hours ago
2
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
|
show 12 more comments
3
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
3
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
2
+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
2 hours ago
3
@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
2 hours ago
2
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
3
3
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
ohh god, why why why would anyone write this code. Thanks
– Gilad
2 hours ago
3
3
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
@Gilad Trying to be clever, most likely! And failing.
– Lightness Races in Orbit
2 hours ago
2
2
+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
2 hours 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
2 hours ago
3
3
@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
2 hours 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
2 hours ago
2
2
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
Of course, that hack is especially useful for macros, which one also should avoid assiduously.
– Deduplicator
2 hours ago
|
show 12 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56094137%2fwhat-does-a-comma-mean-inside-an-if-statement%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
The second code snippet is not balanced - there are three opening
s and two closing
s - it is missing a
.
– Peter Mortensen
55 mins ago
See also here: stackoverflow.com/questions/16475032/…
– Valentino
41 mins ago