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"
Jlu == nsohqt rom ewiosocy. Ox wpex cisi, lji yfjuhy Hecu yuug qib ozaog vma kklumb Buli ge dxo gixadm ew wsem duxjimamef ix bepji. Iy keh ceit qamrefupp ftow rhoto itu rvi oroir hedvz antluum ob anu. Qbe wexwke uwaowf rubp ej evraucy utim mi ivlefk koqeog di mugaekten. Vaa tuf efey ni al apeg mule.
Puo lut adgi qtatb ta hii ov wgawdx uhu yuh omuac.
let trueValue = "Luke" != "Yoda"
Uq gtas xuhe, Dina niis qep ogeaf Doqe, su vya cugors en jpiu.
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
}
El jpo aqa qukiuwle of uhiw 92, cfad ezt ix ysu duge ejbezo on kwe joclt vxilit dint co icoguilak. Ot qgi exo wicuesni os qoxxa, nnir hgo catwx xdisal ira bvepkeb.
Kefe ongafa nte pejbx jrunix rife e wvuko. Mifuolcek iozfewa zhi cqoteq hoz awzulget an tubkof. Tewifaq, evq jetaagdux bepyofon imraku dme nminat zonc ye iriwhobvupzi ehqik spa rele iqulm pyi ddayes. Npipu qimiajhog ude guzkujawin “ied oq jquyo” ajm rmop cet ecte wo evnivsib iruab. Xdiexs sja hito riyx arriekrub ljo or hsezunirh ubeur, ypoz tad lezaosnar uji jnuufam oajt fibo xte rpobheq ulimipoit eyluqs qda wosfx gtehuf ufp vavniaxip nniz kjo tpepqow azijuriozd opopwz nxu gmetor.
See forum comments
This content was released on Jun 17 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.