What we call Ternary If is a short use of the if control structure. You can see its usage in the example below.
Syntax:
condition ? exprIfTrue : exprIfFalse
Normal if else usage:
int height = 185;
String heightCategory = '';
main() {
if (height > 175) {
heightCategory = 'Tall';
} else {
heightCategory = 'Short';
}
print(heightCategory);
}
Using Ternary If operators:
main() {
int height = 185;
String heightCategory = height > 175 ? "Tall" : "Short";
print(heightCategory);
}
Operators and function structures are no different from other C-based programming languages. We will not go into details.