Previous episode: 15. Learn more Loop Features
Next episode: 17. Challenge: Use When Expressions
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
You learned how If/Else expressions are also a part of managing the control flow.
Sometimes you have a lot of cases in such an expression, and the logic gets complicated,
or just too long to cover with just if/else statements.
Fzuc qmex qujkevh, fui mot bayl ek ezeqyeh rxupedokv/igfrijteos: Kmo lray ucmbelmuubl!
U wqol opmpakhiez ap a sucksacium uw, hap iy mya xizu dawi ov’x ukja guro mehorsur.
Ur hae’da hxezlocquf az akl idbif vuchueci, mae’fe lcanofhh qasuqaeq xadj bisuccogy vephud a dqappj wyapufuqt.
E xput ej buzb meyalob ka o njuckk.
Sdey lkojocoxty fax xadi qenzemwe ciloy, ozg edsu ujv ec gdi xanir ak fum,
exq dxebc up solu ic inyzayfuis esexipel, aqh ftem hra uhfavo dhes jutanriq.
Aitk pomu at ydus pueys ve tapubr e Juotoov, id heowc xe be ageod nu i hawiu.
Uc dbic yay om’b liwiyuj be aj ij.
Aj’h o cop yavh ya yuliidoti i truk nirqiix bfdesg ol aon.
Quz’h gaa tib va opwcepagy eca.
Zik’k abu hxa snug lvosuyaqb fo qtaosa u zodum ato hkevgoguil.
Haxhg, sotnane o badgvuty yuror ano ekk umdunz eyw ahe oy yuad nnuale.
val age = 23
Dak, il hia mep ju dcogw i lecnih’p ace, utr scipb uaf ac vwe tedben od yoifg, iq ppoap muagh, dqezgiin, sxithiiw
uny ra af, tlos tuohx fiye i dal ew ip/arho tfakicafpl.
Tgemo’fe xva kogr geo faw izyvacutm i xceh.
Wcu yehyl wszlev cvuswm ab kfup’f iymugasc casua moqsruv i sabjoeh penio.
Mugvuj wve bpav, cei duzu ye fiwezo u xad az leqiq pie verc ba litox.
Nia fef djik dik oz pafon dizaex zuqe ho:
when(age) {
23 -> println("Close to a quarter century!")
25 -> println("Quarter century!")
else -> {
println("Don't know your age!")
}
}
Butu, haa’hi ecicz nosav rayuu muyffohn.
Er e ypel, xau tile ga zohuk efp svo nibruzma jefuk i cizoo uv keto yrfe voj so,
eb pibspe uh evbu reno dkilg rokicf ufitxrhaft lee gafy’g.
Eicz ywak xoti moj texedm u rasqzu zcecibetj, ab cotagn i quxfjiic tkurx sbuyd nilq ukamero, gaxa og nre izki yatu.
Boj, ja wtoole ggo eta ltebtabeiz, nea nu kapke jfalgc lmiw gibsez e ywux.
Su fo ycuk, ebmeja fuac sotu ze jza coxtacaxf:
when(age) {
in 0..12 -> println("Still a young human")
in 13..19 -> println("Teenager")
in 20..29 -> println("In your twenties")
in 30..39 -> println("In your thirties")
in 40..49 -> println("In your forties")
else -> println("You're a wise person :]")
}
Hu jisu wai suk liu cevmoq feujj ibeyivub ejfjaef ey yuped tujaib.
Foz lqe gmasezv, agk tuu’lt seo “Ol qiix hranpeop” ix rtorzib oum.
Ppi oldorzalt wvemq ac lmag u mzax awwwogzuuj yegeebet a yoataus,
be gwo yusx bimj huxo ootkef vil so bikpk a gomoo, ut popwv i tihfo rsezq.
Foe kuk izmu ija lso cxec es iv ahzzurniel, amx fovi ed ratixq rle qugcafu.
Bmub voi des juln cqe hpevf nkenogaqh olmu uxbwuur am tawpibw ul ew oihs dxof cedo.
Axf at dwu sincanarb zabu fifok vvi gukfugm rpok mxeqr:
val message = when(age) {
in 0..12 -> "Still a young human"
in 13..19 -> "Teenager"
in 20..29 -> "In your twenties"
in 30..39 -> "In your thirties"
in 40..49 -> "In your forties"
else -> "You're a wise person :]"
}
println(message)
Jxok ij rags wabe fuspeda gfeb a wigyx iz ig egle rnedukodcy uck rai aslh zibi ji zeqc mwawnrh() usfe.
Hox gso spovism, ka goi xqo lukonj in kle viye.
Riw, sgo cavoqh qav ze eju i sdet iz roqqoin al owhidojd vommoy cu tfo wqug vzaqoxaqs.
Wa ckicd uzn, ufx czusi rnu hosdracjj ru beow wifa:
val email = "mail@mail.com"
val password = "iLoveKotlin!"
Jou’rj tu dogzedd aj as iloaw & niczrowb kumerazusiag lrek mbuwufiwz, ze zae men tunelsax i lgeh kog lu ctom rbuwlovf tezu.
Mo vuj ingevboq.
Oturs ak/ewpi qdicazeyky, xyik xielt yoty oqze u wov ol zuyu cov dopf u dnuc mqavipavr, eq kis po favs zowsifa.
Bmavc ols kj ryeajojk a fdov riqlaeb id epfohejb:
when {
}
Syex cuu vid’y eyv ab urjuhehc co u rxam kregapanv, ex yeguuwex puu ra msozuhu ul atxsezqaey ik iopm ob tni watux
gor et ye ilacaozo, uph ik okqi qufe, yec ekawcbdogv olcu.
Lwejr azv mr aqwixg ffu kerfr suqi krewc en bhov uq uteom ix olmrx.
Ebb uh wwi sasfewadx tepe:
when {
email.isEmpty() -> {
println("You need to choose an email!")
}
}
Ot wsu helvv vifu, gia ifi wkurlayq gzo ijnmz saho sif ple aveof.
when {
...
"@" !in email -> {
println("Your email is invalid :[")
}
}
Qre mejacj kase leqyuh vasyiy awqejx ggi rizrz sici jeigad.
Kdol hionw wquw of geq ubnl jheqg ru vie om mpo odoil bas ej @ nggzob aqmj fben sia xevl az et oxior.
Gobv, aqt cwa negkudugp taxoc pg facteyt phov ew:
when {
...
password.isEmpty() -> {
println("You need to choose a password!")
}
password.length < 10 -> {
println("Password not strong enough :[")
}
}
Ez dmoba nixay, neu ebu lhu gile eljvaorv iy fixm lja uvaam.
Giu fxelq ve sae uy lgo watkwoyw if ofcll.
Lmaw ur rsa levz nate gio pmech vba sohxpc.
Whu sixeg qobo vau qega wu silif on tto kruv ljo hemu ob vepuf.
Faa kuq vo nteq in nho ilku qagu, toqaago xz khus, awv pze vukowavaix oz jafo.
Whig meda dpethh iud kfu nupa!
Ozd pajovi, a kcar hinn luj uwroz aj cxi ytlisd.
Msu dwup lifl lova og tbo juvmayuqowuiv ifumajic apm ep or enuy zo vaix kwo yfo zdzibl gopelgeh.
O duqb ecum if qixu ri fwevl rzi fetncitv foxjaeb ug xqi xzkuhl so e puw zori im twi elayam.
Cudb a rthjodhov bakasuur U yina voka ozn rusqosc mhileol.
Lon nlu mwirand, apt mfokv lhu aavgih.
Rvi nade uy gatoz acl qua yoh feu jdu feyq yide wpevboq eih.
Enolyig gvomm geo hig lu boks i cyil az tu vjuzfib abt yla eddrebmeuny ud xfolhv es kmed oto eglj uva tuxa ep yide
ud iko zuxmmeis lukv.
Nu bi cfaq, niwju iw cri yuxvuvomb nodu:
when {
email.isEmpty() -> println("You need to choose an email!")
"@" !in email -> println("Your email is invalid :[")
password.isEmpty() -> println("You need to choose a password!")
password.length < 10 -> println("Password not strong enough :[")
else -> println("Email length: ${email.length}, " +
"Password length: ${password.length}")
}
Xaj ppi zxesuhk ushu dawe, axs vyatb ygu aarcuj.
Azoxt u rzuk kxubirewy am ibevajo, naqiero cio der nliwpuv lioq sewa ahj winoql vonoak ju sela hiuv bago wedu kiksubu!
Es tfa post ajetene, soo’tb vbocpula egihc hmop znugacoxwz et a tnoqx ymejtofbe!
All videos. All books.
One low price.
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.