Friday 5 February 2016

Julia: Boolean operators

Boolean and (&&) operator
Operand1
Operand2
Evaluates To
true
true
true
true
false
false
false
true
false
false
false
false


As shown in the above table, && operator returns true if both the operands evaluates to true, otherwise returns false.
julia> a=10;b=20;c=30;

julia> a>b&&a>c
false

julia> a<b&&b<c
true

julia> a<b&&b>c
false

Why Boolean AND is called short circuit operator?
Since if the first statement in the expression evaluates to false, then julia won't evaluates the entire expression. So Boolean AND is called short circuit AND

Boolean or (||) operator
Operand1
Operand2
Evaluates To
true
true
true
true
false
true
false
true
true
false
false
false


As shown in the above table, || operator returns true if any of the operand evaluates to true, otherwise returns false.
julia> a=10;b=20;c=30;

julia> a>b||a>c
false

julia> a>b||a<c
true


Why Boolean OR is called short circuit operator?
Since if the first statement evaluates to true, then julia won't evaluates the entire expression. So Boolean OR is called short circuit OR.

Boolean (!)NOT operator
Operand
Evaluates To
false
true
true
false

julia> a>b
false

julia> !(a>b)
true

julia> a<b
true

julia> !(a<b)
false





Previous                                                 Next                                                 Home

No comments:

Post a Comment