0
When should I use an IF statement? When should I use ternary operators? Why?
2 Respostas
+ 2
suppose if u want to print a value based on few conditions like
print 'a' when it is positive
print 'a+1' when equal to 0
print 'a-1' when it is negative
then u should use if - else if.
however u can also use ternary on it but using if-else if increases readibility of code
use ternary when things are small
0
just remember one thing performance wise both are same but multiple ternary operator sometime create confusion. otherwise they are same as per apple documentation