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

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!

Leave a Comment