Let's assume that you want to decrease a value until it reaches zero and stop there.
if(value > 0) value --; else value = 0;
An alternative to the previous code:
value = value - 1 < 0 ? 0 : value - 1;
value = Math.max(0, value - 1);
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.