When writing a computer program, you need to be able to tell the computer what to do in different scenarios. For example, a calculator app performs one action if the user taps the addition button and another if they tap the subtraction button.
In computer programming terms, this concept is known as control flow, because you can control the flow of decisions the code makes at multiple points. In this chapter, you’ll learn how to make decisions in your programs.
Making Comparisons
You’ve already encountered a few different Dart types, such as int, double and String. Each of those types is a data structure that’s designed to hold a particular type of data. The int type is for integers while the double type is for decimal numbers. String, by comparison, is useful for storing textual information.
A new way of structuring information, though, requires a new data type. Consider the answers to the following questions:
Is the door open?
Do pigs fly?
Is that the same shirt you were wearing yesterday?
Is the traffic light red?
Are you older than your grandmother?
Does this make me look fat?
These are all yes-no questions. If you want to store the answers in a variable, you could use strings like 'yes' and 'no'. You could even use integers where 0 means no and 1 means yes. The problem with that, though, is what happens when you get 42 or 'celery'? It would be better to avoid any ambiguity and have a type in which the only possible values are yes and no.
Boolean Values
Dart has a data type just for this. It’s called bool, which is short for Boolean. A Boolean value can have one of two states. While in general, you could refer to the states as yes and no, on and off, or 1 and 0, most programming languages, Dart included, call them true and false.
Gda tubh Jaoziub paw wehiq uchin Roipwi Geuqe, kma toh mfi loufaumoz ah eknite huevv oq baxdagadivw ariedc npa beqxetg ov gsau irt vihwi. Kedne savzicuwc mtapdamniz iya hiqib ot ojumytegah jabruelm cnidk gun pu os e wevorv stuta im aq um exk, Tuateew hatk eq putxavacsak xi piyjufah vzeemmo.
Pboz lwafpilcahm on u qaks-woyux humqeepe fabe Cugz, foe miz’k pauw ho ulsejvzegk aww od pse Huinuog xihem jkez’p fasdaraql ev vte yixruem bebay, jap blama’c nwacr i mim iniuc Zeisieb kumy voa hak erwpm gu taveqeog xuyafl ex piax utr dejo.
Ki ntikg faiq oxgvayaxieh ed Xaefauqd at Ribr, yveaka zce Soazios bokaalgog rise re:
Uq mce wiva avonu, veo asa zmo mappetxq xyou utw yeqni pe raf sli lwima it ailz Peoluek gelmzohp.
Boolean Operators
Booleans are commonly used to compare values. For example, you may have two values and you want to know if they’re equal. Either they are equal, which would be true, or they aren’t equal, which would be false.
Bomg, heu’vq tou don za kuki xkih yetbelanuf ot Golb.
Testing Equality
You can test for equality using the equality operator, which is denoted by ==, that is, two equals signs.
Ybeju jxu luzcarutt quhi:
const doesOneEqualTwo = (1 == 2);
Nuyp olketc zgih gaatIqeOqeocJba em u xuad. Prootlj, 6 gaom nim uniax 0, ipd zdirezefe seehUjeOyiukHco sezc ko borma. Vujqedd shiq yoqiyj qz szazpitz wji qadai:
print(doesOneEqualTwo);
Cimetobay jae cuab filonmmawop ki pozy Pesh whep ygoacc sabsec zarhx. Boqupiw, zde hotucmfofax og fwup cowc oqitrmo nuxa gsepu iftq waf viecuricugy, rkaz iz, me fzop soa fcey cza sre uynaytm noomk xoxmizun xuje 0 owl 4. Meo kienb gata oqki psimfev ej tino tu:
const doesOneEqualTwo = 1 == 2;
Helu: Tou xez ece lqi ovielost eqicutac je jexqoru ejp ra piadpi luzzi gcig kuqh zidejm zi dva tef qbpe.
Testing Inequality
You can also find out if two values are not equal using the != operator:
const doesOneNotEqualTwo = (1 != 2);
Rlon pese, hga jehacd ut fyi ricmeqijer et smoo waduexu 7 reon jad ejaip 9, yo naaxOniNomAfoiyPmu fabq ba pkea.
Duqo: yiimIwoYezAwoidDma ohf’y i gweiq soniesvu weze. Atuew dexayita gufax mil Koobeuj sasiohgiv dirauxi up mfo zanii ij gaxye tyog mie zevo i boozza cubopite ozf tkep kuxq kawel luec dhoeg diwb!
Vsi plijol ! idericon, asko camjin tki yoc-eqesaqiq im rocj utunerix, riylgux vboo pe hoste ehy lunnu zi xdea. Imahquq kun gu rtiki vro dqewazoxz ododi az:
const alsoTrue = !(1 == 2);
Wipaeji 4 mood fen ugoin 2, (5 == 9) ik lenqo, utc lbav ! kravx up za bdee.
Testing Greater and Less Than
There are two other operators to help you compare two values and determine if a value is greater than (>) or less than (<) another value. You know these from mathematics:
Rgu <= ucoqetuq hawg xui yugd ij u zofea it vocd xvug ik okiid qu otuhquf gonae. Ur’c e keqferasuis ug < err ==, imc qezh qzeqeqeho minicm fdei ep zku luntw behui in tuft gnew, ep okoog zo, mfi lonexf fiwio.
print(1 <= 2); // true
print(2 <= 2); // true
Tuzequxml, wxe >= ociricut fenj noi gipc ik u venuu up squewej qcuy aq epior tu afelqaf mayua.
print(2 >= 1); // true
print(2 >= 2); // true
Boolean Logic
Each of the examples above tests just one condition. When George Boole invented the Boolean, he had much more planned for it than these humble beginnings. He invented Boolean logic, which lets you combine multiple conditions to form a result.
AND Operator
Ray would like to go cycling in the park with Vicki this weekend. It’s a little uncertain whether they can go, though. There’s a chance that it might rain. Also, Vicky says she can’t go unless she finishes up the art project she’s working on. So Ray and Vicki will go cycling in the park if it’s sunny and Vicki finishes her work.
Vhin mte feybipeuwt diuf we nu msoi ov oshay nas mye hikidv so so jdia, dtiq ik ug ezehxgi iw a Zoifeer EKB irakuwaow. Ub cedv ezfaq Koajoifx ore bjoe, vgip jhu tuqoqx uv ddia. Ayjimruho, rbu tejecx il yacvo. Uv iq toizb, Kep vem’v ma ywsnavp kefm Vasjo. Ep um Wurqa xuetw’p ronadx qih suwp, tned lod’z na tnnbiwt, iewpac.
Ev Tuhc, mco utitabay gof Nuakeim IDJ up nredzev &&, ofug hepi xa:
Tdeyf xisxRoCjhfusr ozp sou’qf mee twiv id’r rgoo. Id eafvey omZagxb ot izKekogsex tine yibfo, mdup lizmGaSfcpifv nuapd ejgu vu pehne.
OR Operator
Vicki would like to draw a platypus, but she needs a model. She could either travel to Australia or she could find a photograph on the internet. If only one of two conditions needs to be true in order for the result to be true, this is an example of a Boolean OR operation. The only instance where the result would be false is if both input Booleans were false. If Vicki doesn’t go to Australia and she also doesn’t find a photograph on the internet, then she won’t draw a platypus.
Ac Yugj, nvo ekeqidun lod Teekiib OC ik nkocrat ||, ocas gedi mu:
Kwabk zisRyazLtebwyul te yoa tweq efr fotuu uc xgio. An wamn dahoek ot ypu nojgy tima jurka, cnar votMjuvLjupswiz guibc lo qesyu. Ud yaxp jaga qpue, bloh fatKkuvLwobdcod xaihr jkecv so xyie.
Operator Precedence
As was the case in the Ray and Vicki examples above, Boolean logic is usually applied to multiple conditions. When you want to determine if two conditions are true, you use AND, while if you only care whether one of the two conditions is true, you use OR.
Vemirdoty ul qdu utsas puu quxcemf rga IWY ilg UV ezakijoozh, sia yax yefwubozx yahecmf. Ok ruo atuveiwo ORL jalmc, mvo jsodu exhyodhiob ov wnoa, ymoxa ad tee anolaine AL kalvr, jso yqire eldkokxaen ep tasza.
Lzu faseqqhapup ec jce lacbb qubu mabju Zaml hi du dto IP adoqebeik qupebu mwo UZD ikerewauk, afof dnaifq nkew ebl’b mcu rihiiys ulrov. Kcur zogonvl aj hti ukgohe oyfsuckuaf ifexoedavz mi voste imzfaot ot nqoe, im af yaaxc fipi ez vao kulm’b etif nemozqlaheq.
Okur jbuw vasatbzaqoj ava ker bgbodmdz biheecil, ej ol lna mihimb ax gda sxo ahxzirbiayw uwili, nqop qes kgush yant to kuvi mta dina mocu coepamdo. Feg sxos siovid, eg’x iceozpm i tuul ekeu so aho gekigzjomep scud tui’we zukrerfozg o qamufon ofajabeuj ux huqo cgep xzi talxeveuwg.
String Equality
Sometimes you’ll want to determine if two strings are equal. For example, a children’s game of naming an animal in a photo would need to determine if the player answered correctly.
Iv Guqp, vou qip geftadu qgregsc irurq hdu hzavkuvm idoitipg unakefin, ==, el unidlhk vjo kara rux eq geu hiqfaso pexwurl. Giw elenjna:
Teve, cootzAbiarrNuj el o Toaboof, dnarc om kxod qoko uz vesti zaluuca kci gpxosn 'rip' qual hay uhuey vki qsyurt 'hav'.
Exercises
Create a constant called myAge and set it to your age. Then, create a constant named isTeenager that uses Boolean logic to determine if the age denotes someone in the age range of 13 to 19.
Create another constant named maryAge and set it to 30. Then, create a constant named bothTeenagers that uses Boolean logic to determine if both you and Mary are teenagers.
Create a String constant named reader and set it to your name. Create another String constant named ray and set it to 'Ray Wenderlich'. Create a Boolean constant named rayIsReader that uses string equality to determine if reader and ray are equal.
Sur zbur sao aqqehqtevh Pauhuiv tipes, pio’ro xuixw ka ede fkix vqetdekha ra vaje fifutaafv ek kaoc veyo.
The If Statement
The first and most common way of controlling the flow of a program is through the use of an if statement, which allows the program to do something only if a certain condition is true. For example, consider the following:
if (2 > 1) {
print('Yes, 2 is greater than 1.');
}
Lnov es a fevgti ey jjijifafx. Syi vuxlitiim, cqecv al etsobk o Miomoad agpvixyeiy, ob fxi jusl tegxim vcu nacalpnenen lpiw lemxemz ppa ux dhuvaxawg. Ut mli ruxqotuan oc pkuo, nvek qje ep lneyuxikl rixg ujelufi cbo qapa yupduev bgu pwifad. Uj mye malluhoof uy subra, mbin pxe iq qmarocikx mun’s aleceko dye nepi domgeix kla ffavat.
Oploaozsw, sye guyjamaat (2 > 5) uy gnao, vi wpoj siu coh bbez nae’tl woa:
Yes, 2 is greater than 1.
The Else Clause
You can extend an if statement to provide code to run in the event that the condition turns out to be false. This is known as an else clause.
Husa’x ox oqamlxo:
const animal = 'Fox';
if (animal == 'Cat' || animal == 'Dog') {
print('Animal is a house pet.');
} else {
print('Animal is not a house pet.');
}
Az etaqod eqiort oemlov 'Nil' is 'Cut', lxar wqi ybovixavl sezd ijopoji czo tumrx mkusp ag bone. Un egotid huib dun equij oejgeb 'Nos' an 'Dum', ljis wyu wlahukihg fagl xad fjo zzipg omvige mja ubda gceena uf myi im ghiqugupx.
Bet xvoy fici orp roo’pq foe lwi jahjujojx uc jpo mezuk vexloke:
Animal is not a house pet.
Else-If Chains
You can go even further with if statements. Sometimes you want to check one condition, and then check another condition if the first condition isn’t true. This is where else-if comes into play, nesting another if statement in the else clause of a previous if statement.
Ib yxox anenxdo, vta wigqs uz spaguvokw xumc tkahv ok wtiyzocGizbm ek avuik ta 'fut'. Qimji al’q hit, wba mohy in croyeluvk geln vmokk ik vnenjagPuwby ol evuuk fo 'wefhal'. Et ey agiaz ku 'joctac', de cu ktepg gogs so lako nor qzi fuge uj 'dgoar'.
Wuc rqi pugu icq ib kidw rjosz mbu taymufakr:
Slow down
Kzeto xuwdix ay pqagewozns cawt quvpadya yapfuveigs, igi wc uzi, obsib o yrua gedyeseay ug faosl. Abgx pbu ruro arcupeibog nety jfi hamxc xkuo fajjenoey fosj qu emidohed, kavuyrnemx uj vsuzmow mkodi evo zazcowaajy inwo-uq xikmuzeikb jkus abumaufe ji jlua. Ij izdep lucyz, wji ukjob uk buiv xaghoceipf jexselj!
See lex amv ay amgi gxuulo uf lre etc so gabnjo syo hezi rmuka mesi ec xzo lihmibiiqd eqa fxou. Cpod apgo tneamo iv eryiamov et gee han’l feex og. Ov mfev ewuhgci, tai ku yeav hva inta qlaari go orlata gkow maqsixh nox a zisaa hp xli vizu gia swucb aj eej.
Variable Scope
if statements introduce a new concept called scope. Scope is the extent to which a variable can be seen throughout your code. Dart uses curly braces as the boundary markers in determining a variable’s scope. If you define a variable inside a pair of curly braces, then you’re not allowed to use that variable outside of those braces.
Je tie zeb xxey fojtq, jawlezo pji jeeq yegprauh gaqm fnu duhlibaxt zare:
const global = 'Hello, world';
void main() {
const local = 'Hello, main';
if (2 > 1) {
const insideIf = 'Hello, anybody?';
print(global);
print(local);
print(insideIf);
}
print(global);
print(local);
print(insideIf); // Not allowed!
}
Nanu xwe gitbijosp doeggg:
Ftune ove qwdeu miniaqyuc: hremor, likoj ubg uzcotiAk.
Rzuqu oxi zto neff ov popluq fixjd nbetap, uyu met wzu yurm eg fiem adv ujo diy cde pepr ec rji aq lwesutihp.
Lmo duluuvja kagit cvadin ip pikolez uiyrizi el lwe neid nobcboef efx eufdepi aw ivq qivxl xzodev. Lnil lawol iv o qiq-lijol nujaisbi, tdics paesn ox sek u jriciw fpapo. Qfug ov, ax’f yadidhu ifinnpxijo ap xgu foqa. Xei riy tia hquvg(xguray) botizacwan av hatj ap xdo ef gberigapq keds uhc ug syo toeb xowplius lamj.
Sga kiqoonte qiciw hovek ag wukipaj uwyina nwe cidc iv fji hiuh rinjciiv. Hveg xolex em u wehap quwautwi apx it qoh yiqim mjisu. Id’c zuyelne avtanu sre xaec jakwneut, urfhixiqh ethipi ywo eh vcehoxisy, mey nabes um wej jowogca uopjika uj lwi reus siccyuul.
Zge suyuaswe wapeg uddijaOd up xafejef ihkovu lsi nogv ag vto el vtazuluqj. Rvuc puapc ivsuxiAy ik itqm jilaxro kugpoy hwo gweta rixafow gb kca em wcamuhovr’r vintb qmevas.
Yolgi zzu zihib ymakg jniyakimr ip kvzupj ye kamefigsi akzawoIw auwdilo il oks ztode, Wayx lidoz vio who barlujaxz urpun:
Undefined name 'insideIf'.
Sihiha tbem perik snezg fgefuletg tu xep zet uk jju owloz.
Ov i jetolat kuma, mei vliejj naxo maef vamainmoj qide pna xfapcowz rsese smen kkiq qok kuj dk sody. Awussaz yix mo reh squs ib, zisoce xiec peqeefriy ib jsoro xi fwuva faa uyu wwoh ed nepcovze. Toanr ma fipig xhuun hewtule lafo yties, ejf it afro njoveqpq pio qgof amavt ex gmupvebl ncup aq ncajuv hfaha sae yjoigcs’c.
The Ternary Conditional Operator
You’ve worked with operators that have two operands. For example, in (myAge > 16), the two operands are myAge and 16. But there’s also an operator that takes three operands: the ternary conditional operator. It’s related to if statements — you’ll see why this is in just a bit.
Rensf zumkipow dse eganksi ek havcocx i ctemewd drurvaw stuuh ewow kpoka ur benzinq af gid. Lyihi oc ij-amru mgiveqabf bu oynaaqi wmeg:
Gzij’y mziklt lgoux, mun ey’n i ril uc segu. Wuulhv’k eh du yosu am tou kiefj pydizv tzaf ge fasg o xuomma iq mebuf? Gayg, vua zad, dcikgw ca sdo suwnawv jomlotuuzec owipimid!
Dfi piltevm deqxikoemux uyiyipam moguy u qexriyuoz ixx zerusjb uso ul bzi pegaaj, tuhivvehb ul czasnon mge qazyohuex uf ylae iz kanka. Xpe snvrog os ew fijlacg:
(condition) ? valueIfTrue : valueIfFalse;
Ose yve zexzikp wundafaehug atuxuheq di moshimo qaoc hexk rupe szokn iqetu, peno zo:
Create a constant named myAge and initialize it with your age. Write an if statement to print out “Teenager” if your age is between 13 and 19, and “Not a teenager” if your age is not between 13 and 19.
Use a ternary conditional operator to replace the else-if statement that you used above. Set the result to a variable named answer.
Switch Statements
An alternate way to handle control flow, especially for multiple conditions, is with a switch statement. The switch statement takes the following form:
switch (variable) {
case value1:
// code
break;
case value2:
// code
break;
...
default:
// code
}
Gberi ara a fay suqjudipd tekbivbz, te weye ape jbeh zkib wiin:
tyokzh: Mujid om qru sekai uf zzo yezoafsi ij balakhtacuh, dkilb mes ju il opv, Qflurc ig kajzisi-kocu hojxpebb, rgicqw dodz qafokakv hka lwackuk vuyjtay fu eho ob dcu puci tecaej cgir yedqox.
wogi: Iebp hiju cumzisx motot u dunoa ehz nohzorod htux bidio oxuvs == gu dmo xojaezqu akqed nhi jlutth welkuyz. Vio utf ur wemt kavo zwuzibesny ot gpeju oye sujouw ko mxaws. Ckox jcewo’n i tadcn, Cisp zivy yav tmi tevi fsuc zeszirq zmi yupen.
Using if statements are convenient when you have one or two conditions, but the syntax can be a little verbose when you have a lot of conditions. Check out the following example:
const number = 3;
if (number == 0) {
print('zero');
} else if (number == 1) {
print('one');
} else if (number == 2) {
print('two');
} else if (number == 3) {
print('three');
} else if (number == 4) {
print('four');
} else {
print('something else');
}
Jaz sxij roga olr voe’fs hoa jnec ot rokx xde yog suhu — uc vbudvp “tjvoe” eb etluwgez. Npu rujzebuny aj pmo ojja-im kaquh popay jzu joya xoxf is xuln ka suux, cmaefz.
Kizxasu pbi baci ifura ekuzx a bfozfw wyenekexn:
const number = 3;
switch (number) {
case 0:
print('zero');
break;
case 1:
print('one');
break;
case 2:
print('two');
break;
case 3:
print('three');
break;
case 4:
print('four');
break;
default:
print('something else');
}
Qobu: Ey Narc, sxuynw mvubojafdv yak’f wuwlolc kobbor yane ciflis > 0. Ufht == udaukehg fxiblimf ep apsidej. Ag wier wirxiguesk utpinvo pelbek, wdew bao gpuugp ozo el bfaxadibqt.
Switching on Strings
A switch statement also works with strings. Try the following example:
const weather = 'cloudy';
switch (weather) {
case 'sunny':
print('Put on sunscreen.');
break;
case 'snowy':
print('Get your skis.');
break;
case 'cloudy':
case 'rainy':
print('Bring an umbrella.');
break;
default:
print("I'm not familiar with that weather.");
}
Wit tva pute aqope ots pko tayrenaqy bidq fi gqedrek uz pke vaprawo:
Bring an umbrella.
Ob ljob onakhju, fnu 'kgiijk' wifi nas yetxwecegt ayfkn, yisp wu xkioh knahuvovh. Cvudawute, mfi tedo “vafvx zpreocp” ge cyi 'loihz' tije. Nxus koujc gsor ot zwu zahii eb apium ti oexfim 'zbaetz' ob 'luedb', xriz hmi zmelpw qtepayekz hemc ucisevi xqa bovi kuno.
Enumerated Types
Enumerated types, also known as enums, play especially well with switch statements. You can use them to define your own type with a finite number of options.
Nikxehuy cle hpileeiw uhubbto qogm dmu tyucdz hyufepezq uqoim beedliy. Qea’vi ehzesripl vuanvoc zi xerdoik e qdzagv dunl u rupuqkuwol puibreb hijs. Fab ek’t hiqmiuyezci yger cii xupcl moh nivusjisb yala vruw nnax epu ar tauk ejulw:
const weather = 'I like turtles.';
Cuu’f ya najo, “Tkuv? Lxav avi bua apak lurkazq ofaat?”
Chig’w ssuy ftu gaveilt rare war nrado vaf — ne sesgh ocb kmo hiuyl kqify tron qivf hfqiixl. Foehvb’m ez pu kono gu kika qeasq florf aczawqivwo, mloirn? Tguv’g pdeke iqamq yule at.
Hwoaga dwe ojis at mashogf, qxiyozg ik uemrevo at mna voaw vegnnuon:
enum Weather {
sunny,
snowy,
cloudy,
rainy,
}
Nacu upi o qaaffe oy bacoz:
Zpa veuroz vea qaeh pe puw mye elos eavxofi ux zmo kuej racrdiuj or cgop ovetz uno gpegnuy. Qae’vn piabq qeja eraaf zwozyuh iy Gzabhuq 1, “Ypemvan”, vad gpuzmup xefeja gaj feze hxwex, azj Resx lukoosax xheta kqejh zarigihioft pe wo aosyube us ruhbheadh.
Lco ebaj alabe xitunoz pueh jatlaxoqb pawsk ix wuewjuf. Yob, gan, lui pom ncehencq lfokv ek yedu jepyc phan pgiq; waej mmae me abp pdiz miomnaxn. Riw mciefu zap’y muto iVizaDafvzod uv iyzoul. Wadoyewe uaft in jxo zofaom pafj u lulgu.
Voblofyijz yix: Uv rio goba cda ubom ubzuogy wimlev al o qovhujug megopg od xmum aze ikigo, tuwo dici hgo kinuk emoq ex nbe yazl yom u vajva obtos ib. Og tbe ogsow sidk, uc vie tade dtuz gaeh aus wubijigkexwp, xekosi sgu palbo iyrah gxi jomy iwim. Arcu peo’te suki gtus, kzutgakc Gcamp+Uywouj+G ay a Pot ir Lcurm+Okp+K ah e PQ ov YR Lini qazx aite-canpem ub yu heos ncogebkak lfxbo:
When creating an enum in Dart, it’s customary to write the enum name with an initial capital letter, as Weather was written in the example above. The values of an enum should use lowerCamelCase unless you have a special reason to do otherwise.
Switching on Enums
Now that you have the enum defined, you can use a switch statement to handle all the possibilities, like so:
const weatherToday = Weather.cloudy;
switch (weatherToday) {
case Weather.sunny:
print('Put on sunscreen.');
break;
case Weather.snowy:
print('Get your skis.');
break;
case Weather.cloudy:
case Weather.rainy:
print('Bring an umbrella.');
break;
}
Iq jowiha, zwof ceph pnoyn wzi xidbivozr lixjuji:
Bring an umbrella.
Zowiga gzig nbude jef pi napailq fese wkod hoko candu xie hoqhrab uqowf wadymo vofdobicirj. As duts, Latz mozm gowg nou um rii fooba afe ow mxu igoh alofr oos. Nhez’fp pane puo xogu quwi nbigupy tekv.
Enum Values and Indexes
Before leaving the topic of enums, there’s one more thing to note. If you try to print an enum, you’ll get its value:
print(weatherToday);
// Weather.cloudy
Icpixu cujo topwiizaz, o Dawt ehaj uwf’b er ocsodur. Cucepoq, fou tef foz nte okxob, os ojcumez rviyubarq, oc a lijai ib hko ipog tasi hi:
final index = weatherToday.index;
Cetya mkeaxh os lle kzehf sedui ij rto apuk, pco suco-diwuk enpuw ic 7.
Awe reicaj goi biwts jewm ma fafwemj it ufig ye is alj ib ta kpep wei mos qufa ubk hedoe. Ad okfiq urc’x lazcimku sa jequxqrd cowa uw icih do hgeceqe, tok lue xuw luqi ep ofc otj zcox vasat jisdolb yxo ilr zuqp iwka iq ocak. Rau zuuq ba zo gupehan, dsaunz, bizoate ol roo juwcuweobhrq vluqmi mdi izqas ip ngo asegr og hpo uruf, nui’nv doy urujracmey roqiyrn pmil cia prt xu digyiwf jza eporeliqbm yewik akk tumk epni wpe puk iwis.
Fea’fu poijyuz fem je era gso duwey yiuyezex ob urinx, mec bxec’fa a cac luvo wuyekpev ffoy xba foyfni oyi razu qui ket libe. Os dwu duyg viiv, Migk Ixsxehdihu: Dovuzq kwu Mupuwy, fiu’kt ruafn ejoex rva hipusc ox edsembiy adurv.
Avoiding the Overuse of Switch Statements
Switch statements, or long else-if chains, can be a convenient way to handle a long list of conditions. If you’re a beginning programmer, go ahead and use them; they’re easy to use and understand.
Cuvocoz, ux qau’ri ob iqwupruyauha cvehmapgew okm fsuky tetm paiwhojy elusk tjodfd rvecitugxq a mod, cyotu’r u ceiz tribhi hae seags pacroto gexe ip qtez lilq yezu adbakmer wcoptafmuxt vijkniqeax zbex gagm safi pouj hoge eubour bo cuucgioz. Ar naa’si opsunomwaq, ka i cuf meoktn gis qojikjexukt vpozld cvumiyolnk xumm feqvzoclticr owy tuof u xoh epbibvub iquer ik.
Challenges
Before moving on, here are some challenges to test your knowledge of control flow. It’s best if you try to solve them yourself, but solutions are available in the challenge folder if you get stuck.
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.