Reputation: 23
I came across this line of code yesterday:
if(flag[j] == 0) q.push(j), flag[j]=1, val[j]=0, parent[j]=p;
I didn't know we could write multi-line if statement like this and couldn't find any article related to this. Are there any downsides of using it?
Upvotes: 1
Views: 399
Reputation: 36419
if
statements apply to a single statement. Normally you would make multiple statement into a single statement using braces.
In your example the comma operator is being used instead. I can't think of any good reason to do this, if you need to use multiple expressions use braces. Using commas is harder to read and will confuse non-c++ experts (and even some experts, the comma operator isn't a widely used part of the language).
Upvotes: 4