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=" |
<syntaxhighlight lang="kotlin"> |
||
fun logicalDemo(b1: Boolean, b2: Boolean) { |
fun logicalDemo(b1: Boolean, b2: Boolean) { |
||
println("b1 |
println("b1 = $b1") |
||
println("b2 |
println("b2 = $b2") |
||
println(" |
println("non-short-circuiting operators:") |
||
println("b1 |
println("b1 and b2 = ${b1 and b2}") |
||
println("b1 |
println("b1 or b2 = ${b1 or b2}") |
||
println(" |
println("b1 xor b2 = ${b1 xor b2}") |
||
println("b1 |
println("not b1 = ${!b1}") |
||
println(" |
println("short-circuiting operators:") |
||
println("b1 && b2 = ${b1 && b2}") |
|||
println("b1 || b2 = ${b1 || b2}") |
|||
println() |
println() |
||
} |
} |
||
fun main( |
fun main() { |
||
logicalDemo(true, true) |
logicalDemo(true, true) |
||
logicalDemo(true, false) |
logicalDemo(true, false) |
||
⚫ | |||
logicalDemo(false, false) |
logicalDemo(false, false) |
||
⚫ | |||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
b1 |
b1 = true |
||
b2 |
b2 = true |
||
non-short-circuiting operators: |
|||
⚫ | |||
b1 |
b1 and b2 = true |
||
b1 |
b1 or b2 = true |
||
b1 xor b2 = false |
|||
not b1 = false |
|||
⚫ | |||
short-circuiting operators: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
b1 |
b1 = true |
||
b2 |
b2 = false |
||
non-short-circuiting operators: |
|||
⚫ | |||
b1 |
b1 and b2 = false |
||
b1 |
b1 or b2 = true |
||
b1 xor b2 = true |
|||
b1 |
not b1 = false |
||
short-circuiting operators: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
b1 |
b1 = false |
||
b2 |
b2 = true |
||
non-short-circuiting operators: |
|||
⚫ | |||
b1 |
b1 and b2 = false |
||
b1 |
b1 or b2 = true |
||
b1 xor b2 = true |
|||
not b1 = true |
|||
⚫ | |||
short-circuiting operators: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
b1 |
b1 = false |
||
b2 |
b2 = false |
||
non-short-circuiting operators: |
|||
b1 and b2 = false |
|||
b1 |
b1 and b2 = false |
||
b1 |
b1 or b2 = false |
||
b1 xor b2 = false |
|||
not b1 = true |
|||
b1 && b2 = false |
|||
short-circuiting operators: |
|||
b1 || b2 = true |
|||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||