18.02.2014, 20:53
Ternary operators exists to reduce the lines of code, and make the if statement somehow, more "flexible"[I can't describe it in a better word]
For example, you want to add "1" to the variable "randomvar" if the variable "tfalse" is true, or add "5" if the variable "tfalse" is false.
In the traditional programming, you would do this:
So, with the ternary operator, you do:
Smaller, more "flexible", and it simply does what you need.
For example, you want to add "1" to the variable "randomvar" if the variable "tfalse" is true, or add "5" if the variable "tfalse" is false.
In the traditional programming, you would do this:
pawn Code:
if(tfalse)
randomvar = 1;
else
randomvar = 5;
pawn Code:
randomvar = (tfalse) ? 1 : 5;