Your First iOS App: Coding in Swift

Jul 28 2026 · Swift 6.3, iOS 26, Xcode 26

Lesson 05: If Else Statements

If Else 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

Back in our project, let’s implement the algorithm we just designed to calculate the difference between the slider and the target value in Swift.

if something is true {
  then do this
}
} else if something else is true {
  then do that instead
}
} else {
  do something when neither of the above are true
}
func points(sliderValue: Int) -> Int {
  var difference: Int
  if sliderValue > target {
    difference = sliderValue - target
  }
  } else if target > sliderValue {
    difference = target - sliderValue
  }
  } else {
    difference = 0
  }
  var awardedPoints: Int = 100 - difference
  return awardedPoints
}
See forum comments
Cinema mode Download course materials from Github
Previous: Challenge: How to Calculate the Difference Next: Challenge: Calculate the Difference