Member-only story

Branching IF Statements in Swift

If-Then-Else

Steven Curtis
5 min readMar 29, 2020

Execute code depending on a conditional statement? Why not?

Why? Because it is a basic building block of coding. You’re not sure how to do it?

Read on and find out how this is implemented in Swift!

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

  • Be able to produce a “Hello, World!” iOS application (guide HERE)

OR

  • Use Swift Playgrounds to follow with the code (guide HERE)

PLUS

  • Some understanding of logical operators in Swift (guide HERE)

Terminology

Branching: An instruction that tells a computer to begin executing a different part of a program rather than executing statements one-by-one

Compiler: A program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer

Conditional statement: A statement that is created by the programmer which evaluates actions in the program and evaluates if it is true or false

IF statement: A decision-making statement

--

--

No responses yet