Why can't I use a “break” statement inside a ternary conditional statement in C++?

北战南征 提交于 2019-11-27 09:44:16

The ternary conditional operator is an operator that combines multiple expressions into a larger expression. break is a statement and not an expression, so it can't be used inside a ternary conditional expression.

You could, though, rewrite your code like this:

while (current->left != nullptr) current = current->left;

Hope this helps!

Why can't I use a “break” statement inside a ternary conditional statement in C++?

Because the ternary operator isn't a statement at all, it's an operator, and it is composed of expressions, not statements. break is a statement, not an expression.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!