+ 2
The Ternary Operator and IF / Else statement.
Is it better to use just Ternary Operator or IF/Else statements... OR I can use both of them and it is not gonna be less readable?? :) I am asking, in case I would like to use both of them but still keep a good visual site of the project. Thanks ;)
3 Réponses
+ 2
Ternary Operator is commonly used for assigning values, while if/else is for executing functions and chaining multiple conditions. You can use both for readability.
// Ternary =========
a = (b > c) ? 1 : 0
// if/else =========
if (isReady()) {
onTextureLoaded();
} else if (isLoading()) {
onLoading();
}
+ 1
Mostly ternary operator are used for small purposes.
Example :
char equalTo[ ] = ( a == b ) ? "Equal" : "Not equal to";
AND
if else statement are used for multipurpose.
Example :
See this
https://code.sololearn.com/WDj7OlB8J2Qm/?ref=app
Hope this helps ☺️☺️.
+ 1
Thanks for the answers !! :)