4 ms·
""" can become led = (pushbutton == 0) ? 12 : 24; or led = (pushbutton * 12) + 12; or led = 12 * (pushbutton + 1); """ It might be worth poi
by randallsquared 14y ago
"""
can become
led = (pushbutton == 0) ? 12 : 24;
or
led = (pushbutton * 12) + 12;
or
led = 12 * (pushbutton + 1);
"""
It might be worth pointing out that the latter two don't actually have the same result as the if/else.
- robomartin 14y agoHow so?
- renata 14y agoIn C at least, pushbutton could be strictly greater than one and still be treated as true, but that would be a different result in the arithmetic versions of the statement. It could be made identical by using "!!pushbutton".
- robomartin 14y agoI think you might be taking what was intended to be a simple example a little too far. That said, "pushbutton" could very well be limited to the values 0 and 1 during the keypad scanning, debouncing and decoding code. Chill bro.
- alexatkeplar 14y agoWhere pushbutton == 2, 36 != 24
- bmm6o 14y agoIf pushbutton is neither 0 nor 1.