How to turn if, else if logic into a ternary operator?

后端 未结 6 1913
执念已碎
执念已碎 2020-12-28 20:12

I was just wondering if this was possible because i started using ternary operators to reduce lines of code and i am loving it.

if (x==y)
{
    z += x;
} els         


        
6条回答
  •  悲&欢浪女
    2020-12-28 20:40

    you should do this by using parentheses like this:

    (x==y)?(z+=x):((x==z)?(z+=y):(z+=1))
    

提交回复
热议问题