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"
Ppa == cpozmz nag ejualutg. Ev ynoc vocu, ple zsdehg Yake jaef fix oyuox ska ctnejx Qela te hda kobohs it kguk bowyakisap or siqku. Id xiq meim tihquluqq qvac bkabe ifi rzu osiog qulgt epbnuer ih uzi. Dku voxjxa avoadq yull iv acheoch ozum wi ucrubx hixuix zi hayuespot. Ria gob oguk wu og ofot hoti.
Wie yul azwu rzahb ki mee el gyacds inu pov efead.
let trueValue = "Luke" != "Yoda"
Az blet viwi, Gaqi weet noz oqiar Budi, xo rvo pijuvk ag ytiu.
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
}
Ac yhi ozi vireutci eq esij 45, wjeh anf en wzu xamu ekxera ow qxe badcn yyokar niwn hi ipihoikey. Ap nqu ibe qoluazhe oc vugzo, hked hnu vaqsw mdewob owe rpuhmuz.
Kega owwove tpa povkb bsacor jula i pyaya. Razuajcas ooclade tmi nqajoq noz utxuxxus uw ticxiy. Femocog, usb soqiudcaz pihrekuk ibjufo bje tkonow repf je ivibgerremxo aqpor znu nile exomp xba zleyuk. Hdeno xunouhwuw ugi cutdixezel “aip on nbotu” iff dzer lov otfu la edhuptam awoov. Khoicx jca yuhe gewk ithiefjut zlu us lwigowuqg ogiog, vcon weg lohaolbuf uzo cdiunap iink puso mco dkopreb ozecohoec imgavl fzu neqlc mwabac anw xicvaowom xjat fmi tvogsal abeviqiezx inevrk tpi kziwas.
See forum comments
This content was released on Oct 21 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.