sometimes I see that they write the normal if and other times the if with the ternary operator. What does it depend on to use one or the other option? Thank you very much
if(condicion){
}
(condicion)
?
:
sometimes I see that they write the normal if and other times the if with the ternary operator. What does it depend on to use one or the other option? Thank you very much
if(condicion){
}
(condicion)
?
:
The ternary operator is usually used when you do an assignment on a single line while the normal if is usually used when several actions are to be executed in case said if is true.
An example of normal if:
An example of if with ternary operator: