Why do ‘return’, ‘continue’ or ‘break’ not work with the comma operator?

That’s because return and break are statements, not expressions. As such, you cannot use it in another expression in any way. if and the others are similarly also statements.

What you can do however is rewrite your expression (for return) so that it’s not nested in an expression – not that I recommend writing code like that:

return x++, 0;

You can’t do that for break because it doesn’t accept an expression.

Leave a Comment