view raw
roboticonx8 roboticonx8 - 8 months ago 43
C++ Question

math operation in while loop condition

i tried to do

while(n++ && x/=10);

but it returns error: lvalue required as left operand of assignment

I know it's from
but is there a possibility to do that inside the condition?

Ben Ben

You have a problem with operator precedence. If you look at the precedence rules, you will see that your while condition looks like this:

((n++ && x) /= 10)

and (n++ && x) is an rvalue, therefore cannot be assigned. Use brackets to remedy this:

(n++ && (x/=10))

Live example.