relationalExpression

A relational expression is a comparison between two values. The result is Boolean: true or false.

Figure 6.23. relationalExpression

relationalExpression

Figure 6.24. relationalOperator

relationalOperator

Table 6.5. Relational Operators

OperatorMeaningOperand TypesResult Type
==Equals (value)Object == ObjectBoolean
!=Not equals (value)Object != ObjectBoolean
<Less thanInteger < IntegerBoolean
Integer < Number
Number < Integer
Number < Number
Duration < Duration
<=Less than or equalInteger <= IntegerBoolean
Integer <= Number
Number <= Integer
Number <= Number
Duration <= Duration
>Greater thanInteger > IntegerBoolean
Integer > Number
Number > Integer
Number > Number
Duration > Duration
>=Greater than or equalInteger >= IntegerBoolean
Integer >= Number
Number >= Integer
Number >= Number
Duration >= Duration

Note: for relational operators, when comparing Integer to Number, the Integer will first be converted to Number.

For example:

var x : Number = tonnage(current);
if (x > 20) {
   println("It is big");
}

Note that, unlike Java, == and != are value comparisons, not identity comparisons. So, the following will work:

def input : String = userInput();
if (input == "dabnabit") {
   println("Censored");
}