Instruction 2

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Assignment Operators

Assignment operators set the value of the left-hand side operand to evaluate the right-hand side operand. You’ve been using this operand since the beginning of the course. :] Value assignment is fundamental in software programming.

Augmented Assignment Operators

These operators combine an arithmetic operator with the assignment operator. With a numerical variable on the left side of the operand, put a numerical value on the right side. Kotlin performs both arithmetic operations and assigns the resulting value to the left side. count += 3 becomes count = count + 3. Augmented assignment operator examples are +=, -=, *=, /= and %=. Update your code with the following:

Exploring Logical Operators

Logical operators are used to perform logical operations. These are operations that always result in a Boolean value, either a true or false.

Fit. 0.0 - 'Jalouvwu op rokuj ijem' nuvzurx
Hoj. 9.0 - 'Poqaefle ib piduq uvux' rifgagl

Equality Operators

To compare two values, Kotlin has the equality operator ==. This operator’s equivalent Kotlin function is equals(). This method is available for all objects in Kotlin. If the values on both sides of the operator are the same, it results in a true. Otherwise, it’s false. In the code below, the price of a banana is the same value as the price of a coconut and a pawpaw combined:

Understanding Referential Equality Operators

Computers store data at specific memory addresses. Multiple variables may point to the same memory address instead of each having its own copy of the data. Strings are a good example where variables may share the same memory address. In this case, different variables contain the same value. Another example is when you assign a variable to another variable. In cases where you need to verify the memory addresses of two variables, use the === operator.

Comparing Variables with Comparison Operators

Kotlin’s comparison operators compare two values. > is the greater than operator. < is the lesser than operator. >= is the greater than or equal to the operator, and <= is the lesser than or equal to the operator. For non-primitive types, all these operators are equivalent to the compareTo() extension function.

See forum comments
Download course materials from Github
Previous: Instruction 1 Next: Instruction 3