Logical operations: Difference between revisions

Content added Content deleted
Line 1,986: Line 1,986:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
Similar style to FreeBASIC entry:
Similar style to FreeBASIC entry:
<syntaxhighlight lang="scala">// version 1.0.6
<syntaxhighlight lang="kotlin">

fun logicalDemo(b1: Boolean, b2: Boolean) {
fun logicalDemo(b1: Boolean, b2: Boolean) {
println("b1 = $b1")
println("b1 = $b1")
println("b2 = $b2")
println("b2 = $b2")
println("b1 and b2 = ${b1 and b2}")
println("non-short-circuiting operators:")
println("b1 or b2 = ${b1 or b2}")
println("b1 and b2 = ${b1 and b2}")
println("b1 xor b2 = ${b1 xor b2}")
println("b1 or b2 = ${b1 or b2}")
println("not b1 = ${!b1}")
println("b1 xor b2 = ${b1 xor b2}")
println("b1 && b2 = ${b1 && b2}")
println("not b1 = ${!b1}")
println("b1 || b2 = ${b1 || b2}")
println("short-circuiting operators:")
println("b1 && b2 = ${b1 && b2}")
println("b1 || b2 = ${b1 || b2}")
println()
println()
}
}


fun main(args: Array<String>) {
fun main() {
logicalDemo(true, true)
logicalDemo(true, true)
logicalDemo(true, false)
logicalDemo(true, false)
logicalDemo(false, true)
logicalDemo(false, false)
logicalDemo(false, false)
logicalDemo(false, true)
}</syntaxhighlight>
}</syntaxhighlight>


{{out}}
{{out}}
<pre>
<pre>
b1 = true
b1 = true
b2 = true
b2 = true
non-short-circuiting operators:
b1 and b2 = true
b1 or b2 = true
b1 and b2 = true
b1 xor b2 = false
b1 or b2 = true
not b1 = false
b1 xor b2 = false
not b1 = false
b1 && b2 = true
short-circuiting operators:
b1 || b2 = true
b1 && b2 = true
b1 || b2 = true


b1 = true
b1 = true
b2 = false
b2 = false
non-short-circuiting operators:
b1 and b2 = false
b1 or b2 = true
b1 and b2 = false
b1 xor b2 = true
b1 or b2 = true
not b1 = false
b1 xor b2 = true
b1 && b2 = false
not b1 = false
short-circuiting operators:
b1 || b2 = true
b1 && b2 = false
b1 || b2 = true


b1 = false
b1 = false
b2 = false
b2 = true
non-short-circuiting operators:
b1 and b2 = false
b1 or b2 = false
b1 and b2 = false
b1 xor b2 = false
b1 or b2 = true
not b1 = true
b1 xor b2 = true
not b1 = true
b1 && b2 = false
short-circuiting operators:
b1 || b2 = false
b1 && b2 = false
b1 || b2 = true


b1 = false
b1 = false
b2 = true
b2 = false
non-short-circuiting operators:
b1 and b2 = false
b1 or b2 = true
b1 and b2 = false
b1 xor b2 = true
b1 or b2 = false
not b1 = true
b1 xor b2 = false
not b1 = true
b1 && b2 = false
short-circuiting operators:
b1 || b2 = true
b1 && b2 = false
b1 || b2 = false
</pre>
</pre>