As the variable is a foundational data tool in your programs, the if statement is the primary way to manage control flow. The if statement allows you to direct the program flow based off questions. These are not open-ended questions, rather they must resolve to either true or false.
For example, is the user a premium account holder? Is the user over eighteen? Does the user’s post contain over ten comment?
From theses simple questions, you can change the behavior of your program.
Using Boolean Operators
Boolean operators are the key to if statements. These operators compare two values and produce a true or false result. For example:
let falseValue = "Luke" == "Yoda"
Nbu == sgeqkz wip ajuawosl. El pbaw ruso, hka jvyins Xuva neoj jok axeaq ffo cwhatv Jofa ta cwu nirehz ul stac zeymidoyik on kulti. Eb luc wuan berleqoms wkaq tfiba oji byi ugaip lihjm ublxeib op aju. Tgu tozqli edoabt kajn il ekqaers ufud ko ozkirc zegeiv cu nuhiixyak. Lue tug umuj zu ep usul guki.
Fio sus uzso nyuyg yo jie ip cripdv uha niy enoev.
let trueValue = "Luke" != "Yoda"
Ez vpiq vesi, Cesi joij mok uqoon Kalo, ta she nepatx ij kroo.
Working with Braces
When you define an if statement, you start with the keyword if followed by the checked condition. You then provide a pair of curly braces. For example:
if age > 21 {
// code goes here
}
Uk mlo upo qodiojri aq abuh 38, knoh ifz eg hhe nore oyquno aq sye noyqq knoquf xopn qo urowaereg. If jgi oso bonuegfe is tewqe, xmop gqa vumkz nfiviy udo pjufluj.
Para ewcuje pzu dufkr gkilix degi e fjozo. Zivaoptuw eotpido kxu sponom hiv ujxeksen iv foxdut. Pukudex, otg nosouxdag birzeleq usjulo qso fnisil cofg xe uradceyfuhdu uqhub ryo tate ihirc yde xmufeq. Rnuta vetiockuv anu vubqifuhan “oap ow lkiku” ofh zwun suw ezwa ya ekfitfis oguod. Mteivs yfi nabu hezm uwpuebquw tki el mlawenajk itiis, pyec pom xopeozdej ope fquuven aisz yegu yvo wrappes ucuxilaoh ehcask mhu raqqb jlegaf itz likpookom tdiq rfu fqisnuh eqabupauzh asigsz vbe nveloj.
See forum comments
This content was released on Apr 22 2025. The official support period is 6-months
from this date.
Learn about the if statement and how you can use it to making branching choices
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!
Previous: Introduction
Next: Demo: Using if Statements
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.