Couple of ways:
1) The ternary operator:
value = value > 0 ? value : 0;
But ... technically, that;s a short form of
if ... else ...
2) Cheat, and use a
while
:
while (value < 0) value = 0;
It's not an efficient solution, but ... it works.
3) Cheat even less efficiently and use a
for
:
for ( ; value < 0; ) value = 0;