Logical operations: Difference between revisions

Content deleted Content added
Galilei (talk | contribs)
Ijo Nanpa (talk | contribs)
Line 1,986:
=={{header|Kotlin}}==
Similar style to FreeBASIC entry:
<syntaxhighlight lang="scalakotlin">// version 1.0.6
 
fun logicalDemo(b1: Boolean, b2: Boolean) {
println("b1 = $b1")
println("b2 = $b2")
println("b1non-short-circuiting and b2 = ${b1 and b2}operators:")
println("b1 orand b2 = ${b1 orand b2}")
println("b1 xoror b2 = ${b1 xoror b2}")
println("not b1 xor b2 = ${!b1 xor b2}")
println("not b1 && b2 = ${!b1 && b2}")
println("b1short-circuiting || b2 = ${b1 || b2}operators:")
println("b1 && b2 = ${b1 && b2}")
println("b1 || b2 = ${b1 || b2}")
println()
}
 
fun main(args: Array<String>) {
logicalDemo(true, true)
logicalDemo(true, false)
logicalDemo(false, true)
logicalDemo(false, false)
logicalDemo(false, true)
}</syntaxhighlight>
 
{{out}}
<pre>
b1 = true
b2 = true
non-short-circuiting operators:
b1 and b2 = true
b1 orand b2 = true
b1 xoror b2 = falsetrue
not b1 xor b2 = false
not b1 = false
b1 && b2 = true
short-circuiting operators:
b1 || b2 = true
b1 and&& b2 = true
b1 &&|| b2 = true
 
b1 = true
b2 = false
non-short-circuiting operators:
b1 and b2 = false
b1 orand b2 = truefalse
b1 xoror b2 = true
not b1 xor b2 = falsetrue
not b1 && b2 = false
short-circuiting operators:
b1 || b2 = true
b1 and&& b2 = false
b1 || b2 = true
 
b1 = false
b2 = falsetrue
non-short-circuiting operators:
b1 and b2 = false
b1 orand b2 = false
b1 xoror b2 = falsetrue
not b1 xor b2 = true
not b1 = true
b1 && b2 = false
short-circuiting operators:
b1 || b2 = false
b1 and&& b2 = false
b1 || b2 = true
 
b1 = false
b2 = truefalse
non-short-circuiting operators:
b1 and b2 = false
b1 orand b2 = truefalse
b1 xoror b2 = truefalse
not b1 xor b2 = truefalse
not b1 = true
b1 && b2 = false
short-circuiting operators:
b1 || b2 = true
b1 && b2 = false
b1 || b2 = false
</pre>