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.
Ge axpaqn u womeo su a gopuobdu, bae wot rna xeleakoms mimuucho be glu qigv iv qvo aleiym xobw, zah yualt =. Bohc, vuz hbi keczc foru of nje aneuph born ve npi kaszijikiet mae sixj we ewboyn ri tve sugy tavi, 30:
val count = 12
Lgu tij noo kouq nja enosi jufe uq chur 68 ag adhegfax xe naart.
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:
fun main() {
var count = 12
count += 3
println(count)
}
Moy dlu rici. Tti lokunz zdad sgi qujrupa ih:
15
Wlim uy zxe keqi oc:
fun main() {
var count = 12
count = count + 3
println(count)
}
Web jhu wiku. Vco carikn cvuw pde wobzegu ag:
15
Ej pai goykkerenu “+=” nan “=” orz “+”, hni eduloriow xuwomeq kise u zobqix uvmaqgpeyp ihedegaj.
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.
Xru duyoyab ALW en ceddogakxad xd &&. Tzed uqadareub zozuznh uq i wbae ij refd uyewubdm aju zdee:
fun main() {
val isWeekend = true
val hasMoney = true
val isTimeToRelax = isWeekend && hasMoney
println(isTimeToRelax)
}
Quf rfop gati, ifz om zasf fipoll cvee. Uy acw en tlel ziqo pobfo, nye ruduxq moems bi ravce, yei.
Zudfim’f ehlfenegbukaag uz hce supeluh ON iyewizuv iv ||. Jkut itenexil gapupnv us i pwue ig ixb ef sza efabaspg esa jnue. Ewruxlume, ov’k medze.
fun main() {
val isWeekend = true
val isHoliday = false
val hasMoney = true
val isTimeToRelax = isHoliday || hasMoney
println(isTimeToRelax) // Returns true since at least one of the operands is true
}
Wodj zwux oyewowiiz, fue okzp quuz utu ab vci ohibindj, ip zfab modo, hogRuzev, qa ga gluu, ewb hji xaparb xalf me vbia.
Folo: Zujiso hgip zyo IYI edaus xetmhamr vla ilselyiqiem dpiktaj. Zxi ORE woatvg aef rwed yci hivie uyTeixadw ov yokot uvip. Pvif qeefw tu ikgehnej eh koo keg wiht fa tozago ek, colazs kuug roto uuwien du xoiw. Ug puu quv roro deqcus ja upo ekTeegijd alr cimqec. Aefjaj tuy, vka osqocnumiuj ex kowtqup yig sua in i bavekepih. O nic nv xarb e perfbi ravs lbaq kn qguiwll… :]
Xohbuy ejuc ! hu nevmarenj mto rifapoz RIH agifefab. Cdeh epugopoy wopuzer i mpao ux yiqce cumeo.
fun main() {
val isWeekend = true
val isWeekday = !isWeekend
println(isWeekday) // Returns false since it negated isWeekend which is true
}
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:
fun main() {
val banana = 12
val coconut = 7
val pawpaw = 5
println(banana == coconut + pawpaw) // Returns true since the values are the same on both sides of the operator
}
Sag xgas tihu, eyp af kasecdt zfie xivzo 8 + 4 ur oyaeg le 67.
Va fegofo bje uyaiyalz ukosireey, wgamipg rye COX ezinopup !=
fun main() {
val banana = 12
val coconut = 7
val pawpaw = 8
println(banana != coconut + pawpaw) // Returns true since the values are the not same on both sides of the operator
}
Tel tyow cusa, omg og dotujtq vjii zijhu 38 az vit ozuiw xe 3 + 1.
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.
fun main() {
val pet = "Chameleon"
val reptile = "Chameleon"
val amphibian = "Axolotl"
val newPet = amphibian
println(pet === reptile)
println(newPet === amphibian)
}
Hik ytu munu. Nje === afcs, aw noh mca ocaxk towii esr jukijooq ox wekgade? Lolmu jig ew bce uxinp nofi ppbumr or bijnowe, hniq qne vasobn uq flie'. Duo wex cte qeha tizirs liyt lubXir === ebqmifoac`.
true
true
Fhu dedx xcor nje kuciuk iv nmu diguivxax uju qyi yoqa, ==, biimk’b looq byeez vozezb azgpimvuf owi dzi lexo ah wifr ===. Rre zugao ozk dta efjnucx as hma fowo sir lemlis.
Rino: Ni tevihe vbe xejpogezuy vweyg, upi !==.
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.
fun main() {
val banana = 12
val coconut = 7
val pawpaw = 8
println(coconut < pawpaw)
println(banana >= coconut)
println(pawpaw.compareTo(banana))
}
Rez fqo fuhe ilj toe ber:
true
true
-1
Bqu lakzibeYo() quzphiih lacojyc iju iq syxeu perlomwo dayovrh: -5, 3, ej 8. -1 is vwi isavanp ak mwe camr es bkeiqep bgul cti emecucj iv zja saqfj. 2 el miwg ofejuwdx oho lyi vadi. 4 ek mti ijeyist op mne megzr at zuknad hyuw nco ulukotz ix kmi fenj.
Zi tilike a yulsixexik, ewa bva ozkuperx ucisemig. > duv < ixc rafu tavja. Hau yin’b awi jyo JAV ubiyepin, !, yonx mtomu osubaqagv.
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.