Hello
Can someone show me how to write 1 line if /else statements?
For example I have this statement with A and B being two variables.
if (A==0) B=0;
else B=A+10;
How can I make it into 1 line?
Thank you
Hello
Can someone show me how to write 1 line if /else statements?
For example I have this statement with A and B being two variables.
if (A==0) B=0;
else B=A+10;
How can I make it into 1 line?
Thank you
// either
B = A != 0 ? A + 10 : 0;
// or
B = A == 0 ? 0 : A + 10;
Or
if (A==0) B=0; else B=A+10;