5-Day Swift Coding Challenge: Day 2

Apr 22 2025 · Swift 6.0, iOS 18, Swift Playground 4.6

Lesson 01: Day 2: Exploring Control Flow

Demo: Using if Statements

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

To get started, open your Swift Playgrounds app and create a New Book. You’ll be working with comparison operators and then putting them to work with if statements. Start with the following:

let doesOneEqualTwo = 1 == 2
let doesOneNotEqualTwo = 1 != 2
let isOneGreaterThanTwo = 1 > 2
let isOneLessThanTwo = 1 < 2
let firstName = "Brian"
let lastName = "Moakley"
let and = firstName == "Brian" && lastName == "Moakley"
let or = firstName == "Jim" || lastName == "Moakley"
let currency = 100
let confusing = firstName == "Jim" || lastName == "Moakley" && currency > 100
let confusing = firstName == "Jim" || (lastName == "Moakley" && currency > 100)
let confusing = firstName == "Jim" || (lastName == "Moakley" && currency >= 100)
let animal = "Zebra"
if animal == "Cat" || animal == "Dog" {
  print("Animal is a house pet.")
}
if animal == "Cat" || animal == "Dog" {
  print("Animal is a house pet.")
} else {
  print("Animal is not a house pet.")
}
if animal == "Cat" || animal == "Dog" {
  print("Animal is a house pet.")
} else if animal == "Snake" {
  print("Animals could be a house pet.")
} else {
  print("Animal is not a house pet.")
}
if animal == "Cat" || animal == "Dog" {
  print("Animal is a house pet.")
} else if animal == "Snake" {
  print("Animals could be a house pet.")
} else {
  print("Animal is not a house pet.")
} else {
  print("Animal is not an animal")
}
See forum comments
Cinema mode Download course materials from Github
Previous: if Statements Next: Loops & Arrays