I have a function with several if ( THIS IS NOT A TOPICAL CODE )
if(n == 1) m = 1; if(n == 2) m = 2; if(n == 3) m = 3;
Instead, I wanted to make them all in :: expression:
(n == 1) ? m = 1;
But this suggests that expecting ':'
Am I familiar with the expression ?: from C ++, where you can simply write:
(n == 1) ? m = 1 : 0;
But 0 is not required here. This is a ridiculous question, and I couldn’t even find the answer on google, as it ignores "?" Like a word.
ANSWER : Too bad that the answer was in the comments. There is no “do nothing” way in this expression, and I have to use if-else or switch. thanks.
source share