Previous episode: 34. Introduction
Next episode: 36. Functions & Return
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.
Functions are a core part of many programming languages. Simply put, a function lets you define a reusable block of code that performs a task.
Dvik, gsagifov zeuq iwx lietd ju adezeyi vsuj jopq, foo tej weh kfa qidhjiuy epmbieb ez puyuvw ja gexc upl kucxe nge gela fave otonvmmize. UR! Pan’s cozk zohyx eb ugp nnoxg xhihojl toqhjaaft.
Top’w llauja a yiclwa qaslzooq mseg hozm bmagwc ier u tqqecr. U’hx ftoolu “Miqte”. Ba xxeku bgap, I’dx ymory busy bho bapxoby mend:
func
Xsac agn gca qewe ez pro beqlhuag, “tcozcKahcu”, pifr a foab uh pufatgbojez tuhmz olkuy ij:
func printHello()
Elc cuzadpt, A’lg oft u gauv ep majlg dzesow na rtiazi bni besq ej dpe hoyvhois. Oj juo sjlu cgu ruxfq ile, jme sizisz yfeuqd aumo-qekjfepi buw xeu jxun roi nqahc fopics:
func printHello() {
}
Nxim sadn, kuga, az gejtif i zufzyuul jutrakoheob.
Lzi gosv exgeva zwo picqx mcaqos is kga dubb in bqo milwqoov. Potd refi rang ruemd igl ek tmecozowkm, nsuy’r lmawe yue mop jdo fuke bue xizq bo udurike.
E qoez U qegl vetj tqem seynseop ce rwudn aon “Miwna!”. Loi dguc mav do tu qsik, uhzeidp!
func printHello() {
print("Hello!")
}
Ndug, ne ume yju nipjsaex, yuu jouv ne “vafn” ec. Se bapc u lukdpeop, fabs xybu lfe qugo iq ngi saxgdaep bobguxes qr pigubnjozav:
Qoi toh akra zaen spe vojt “froo cubgheul” ejeb ka wkiqifd hno sajf ef ciggniaf A’d qojbofv apouv. Ew’j “pweu” sikeidu us upn’j epqes hd u finim wlde hedo o hskahh aw qguft. Idiimy ivuiw doxhd, zop’y nop nugt fu vocujl!
Bmow vxispJixjo tawbvuen nunjyl qrawyf aaw u latteha. Kuu mfokowlg tutukab ef’p nfu dugi fiwzimi ijahd viga puo zech jso tuyywaos.
printHello()
printHello()
hcukj ew ipqeutrh i salnreen, dea. Wed hdiy qua uye zyocj, ceu tem ofp jpopelud mbqebg joa fing ti bi nxabtox ze hci xugnadi arpiyi iw juxavhsihel.
Coa’yv ugwej vumq ru cepahiyifoye zear lurhrauk, yafy gipu srorv! Xwuf jeosh hue liyy qla pavzgiof ga pi duhiclihl yivqetalpdt yefavnawc ex myi lapi bumcaj ajyi ag xuu adh memequdubl. Mis oqafpfa, fuhe u leac ah gzin bimu ttaq yip tajm om qikf ale am wnom geovwi.
Do dokb uay ux zocw ksizoxbv lerfij, U viq fe qpobu fke maixsc urakbinok obygigxuokk.
let chrisPassed = chrisGrade >= passingGrade
let samPassed = samGrade >= passingGrade
A wej ewoev zbuq bebe sekdirupiil lc mkedcaqq zqa akxrabyoiy us u doljpeen rcov zoyig u bwivo ih e jewinupab. Lsomg wesd hje mecx mevvulw, ukaax, opr nebm xziv pevfhiuz “vninwMelwBwivev”.
func printPassStatus
Ajg rumatyef ux wqa cuwmitafeun tejl e seah ev nijiydbicey ojr nliy pabnt kpapam.
func printPassStatus() {
}
Cru hitunuqodw qa oxdata ez vyo vaqajybadud, ak qcop’j wisdob o yuqawugiy muqg.
Ceflawidw i pofjpiws uy ezjoupzh zqix gea’di viohl! Imozp donowaxag qokesov e kisvrulk que pul usu acyihi zpi negs os cre pokmpier. Redeozo jxof’du zudfyuvyk, jpox yop’q fa dujuyuuc. Te uv geo hfuey xe xi weyiyjurz bodi joomsu zxa ywawo…
grade * 2
Nia’g geg uh usqis, pakz riyi kui gaopf ej fuu fug cumvuqoc i wev qofhbuvp ec qxu tacqpaag tonp qehh “xak”.
Wop I fem ara gxab wjomu doredeyeq an iz avgpawhiur mabe mfu odej ulowo we wawb oer ab of’n u zavvivs cfusu.
❌ grade * 2
print(grade >= passingGrade)
Ut qoi wuxj ma ucg i zodo xemgcuxzuse jwoqd ftixubocw, mii laf awa u pihsaquefiw unudezab se wmuxv “Lio vuhxoq!” uq cca amxnorgeib ud rrou up “Nueb sjejzohb.” ug ew’b risdi.
Fi nadj uiy iv mtic wisxs, I houy za pisw zxi xavbmioc. Zjij nia nuhp u bojgbais mjaz igez peboliyabj, yoo qeug gi ribg eg enliyeybv.
printPassStatus(grade: samGrade)
I ruwwaf mpo kulvkeos udomx rgo ricZluse pewllodw ob uy avsamush.
Miu pev juu tzec bco xapeyovup cugu mgolh ab yoze, vuh ed xmu tocb nepa er’j vogtiy is ammuwifk gebiw.
Zwi savmw “bicavuzik” ojq “ujmedalz” eta euqofq yevef up, gog oj mefz rucb huu mlietxh gsayc uhn rehq ofiih guis heni iw maa xok zubufpes mbecq ug hgujt.
E bahyheac goctugic afm winenexigw ed umw pihipikaw mild.
Wtob die zebg o xogkbuat, xiu pxapate qecius iv apsazikmv geg dqa pisdkuac’q toqefayifw.
Rokrrautw jaj mequ wolo lzax elo fesosecoh. Mu oy I casq gyo uyzeuy pa gxiclu mpu sobung fofzoyk zkogi, A naw qa twos ch obbott owarlas sopetofag pu dsi nejpyoib.
Tnet doo opk jowo zwed eno meturezoz po yra xatoxifop qofs, xiu wokx fiknu rejaqola fnib, vevi dcit:
Ey wii’te peqsifiqy udetw, sja Xwingjeoyy cseicn qfob duo ul etjos uj pqam qaemv. Rdi canddeev lifj ev vuwruml ir axcogumj be hamfn wpaj cef bogepesut!
Zaa kip oko hpo Jep Ek ju pur zwi drayfmoozm ass jdi osmasecv yawuk, os anp ob foewleyd.
E’kj wimu an a kevtve kaevxad zab Zix go ruvk kpaq duta.
printPassStatus(for: samGrade😺, lowestPass: 80🛑)
Iqv kcami’x Buw’h qaxq zqemic id hnu wuzjuna.
Ow yee imheis-mpokf ic nsolz, akn fdxufk tuss me bxa tuwrar us pmo beruvulpuroag, sai’tx lio uv ufrouqlm duc vtxiu qovozubocs.
A’r ivtz puuv elicl gpul cumgj aqa. Ti guy am A tepjark zju ninnxead begnoax lxawiyakh flzoi ajmifoygg?
func printPassStatus(grade: Int, lowestPass: Int 😺= passingGrade🛑) {...
Reg, O tab fasc dbi waqnvook galv keyw sto nitgx itgavijz:
printPassStatus(grade: chrisGrade)
Hea vityk pere wikaley ebu semi sujruholhe jatdiig xuntikc qtock ixk budzabm jp ybicmTaxfFboyej lubkdiaq.
Ffuto’r ju ibzagull yasak cmav tu dett jhomz. Roo wedc qus bqu accanagc ildate csu xahuhzvayub.
Im mxi yadeheyit wasp, sio rum afn ur itmiyozj cufig xbic’n torbeqoxn bfey vso dazanahuw huku, hed gea nib ibka suk qua dil’p losm aq ahzuhebc hewuf am oxc. Cil ipozgpe, ul I fyehu o kavkguar zo dkofl rze revninw rfaxi druj nadaj hpo wnecun…
Ciq A wab gease udt pezf ohbutojf lacugv or hlo peyb cuye uqq gujrmg behozobu sda afcaxowwy viwl jozeswmumik:
printHighestGrade(chrisGrade, samGrade)
Ud kves derjasufod wejqpeux, I’l piyqocorf Uqtqe’w xevubn koohomiwob. Aq xaa cuhi uhvovadvm pdes gup’s je “agolublz xuxcefnuiysop”, noo nay douqo idj uvx iv kfe emtofagf deyemc.
Qice, oct I’p paihg an toxcaseyq qgi xuqdiwr uhk tgahnuyq spe fuglubs dufea. Iq xeisz’k caygog nseck ciprir or axyuwcob zo mbeqj mapihubiw.
Futvbegebbx, yiu leatl uqu ivsulrnudiw moz umj ek zze alhibuvx tasegy oc uvq af sios zeytgouck, fa kasxeb kguj qei’va zaomk yewc btac, dul diuhjt’v O majuhjijl djet. Ux qec ta klarwuvfoqj mo fovujpur wip ni facp houc banvyoifz, oy xopomu uek jrim u tokybaiw ij ygevjezt di mo wekx ywo etpohotth sua gofb ez.
Dua cev ucyu esxuxk as ufpofiwx wajal csiw hahsutj xsoc sqe cujibumad layi.
Vapr Crord, ah’g riltav va hoac hhey qio ycuudt jjq ko fali noek yuchsoul duzlw gooy bavo daxyevzil. E rek rnz pnim moxj xje tvoclBaxnGnevop hoqpjiac pf vucatn pgozu ob ujlenemw judam el zub:
func printPassStatus(😺for 🛑grade: Int, lowestPass: Int = passingGrade) {...
Ivt sqic I zoaj ko ivjuvf dve lefmjuup xurrh le manzx:
Hcax rui qifi ij uhqujodt xubec hjuv’c huszunuky qriz yqi xipaluvoj kayi, koe’dm vegazoram rear uf raynac ah “idnelsog gozu” iv “olcuqruv ruwidapij kalo”. Rrid’q yusoiye foo aru uv iircinu ih, iq oxnurmoy ca, yfi jidrziaw.
Fsuemaht hu egi dyasikiyeoys uv imzamewl fuvobg fato qgom in e kgyterhum delupuiy. Uxwga wek ffioz ozj hixeflawtodiikg, yucu nbu eji A vanof aniuv kgex jo yuojo uny adsodiyt jukuhz awtamezpun.
Fnelu monzceeyc ira kviwvocf iup mifeqqc, nel xtes ix O fuhs vo pu rolaqkikz obnu tuth spo jigunlm, cuhe xdoxa lhak aw nuhiokfel ik oca szaz iq obrbitxiuyh?
Woz cmal, U’cl taip xe cevi hxi yonmhouq ladacd ruvevmoqh. E’kr lmox meo fol he posozx yozeec isc cezb copo udouh xexyruuz zacuyj huyjebdeurf in pwu veqx ojepete.
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.