Sunday 13 January 2019

Groovy: Relational Operators


Conditional operators determine if one operand is greater than, less than, equal to, or not equal to another operand.

Operator
Performs
Example
==
Equal to
a == b, return true if a is equal to b, else false
!=
Not equal to
a != b, return true if a is not equal to b, else false
> 
Greater than
a > b, return true if a is greater than b, else false
>=
Greater than or equal to
a >= b, return true if a is greater than or equal to b, else false
< 
Less than
a < b, return true if a is less than b, else false
<=
Less than or equal to
a <= b, return true if a is less than or equal to b, else false

HelloWorld.groovy
a = 10
b = 20

println "a : ${a}"
println "b : ${b}"
println "a==b : ${a==b}"
println "a!=b : ${a!=b}"
println "a>b : ${a>b}"
println "a>=b : ${a>=b}"
println "a<b : ${a<b}"
println "a<=b : ${a<=b}"

Output
a : 10
b : 20
a==b : false
a!=b : true
a>b : false
a>=b : false
a<b : true
a<=b : true



Previous                                                 Next                                                 Home

No comments:

Post a Comment