Intermediate Exercism • kotlin

Booleans

Lesson Overview

# Introduction

About

Booleans in Kotlin are represented by the Boolean type, which values can be either true or false.

Kotlin supports three built-in boolean operators: ! (negation aka NOT), && (lazy conjunction aka AND), and || (lazy disjunction aka OR). The && and || operators use short-circuit evaluation, which means that the right-hand side of the operator is only evaluated when needed.

true || false // => true
true && false // => false

The three boolean operators each have a different operator precedence. As a consequence, they are evaluated in this order: ! first, && second, and finally ||. If you want to ‘escape’ these rules, you can enclose a boolean expression in parentheses (()), as the parentheses have an even higher operator precedence.

!true && false   // => false
!(true && false) // => true

Originally from Exercism kotlin concepts