0Pricing
Swift Academy · Lesson

if/else basics

Learn the basics of if/else conditions, truth checks, and nesting in Swift.

Intro

if/else lets you run code based on conditions. Swift requires a Bool expression inside if.

Simple if

A simple if runs its block when the condition is true.

let age = 20
if age >= 18 {
    print("Adult")
}

All lessons in this course

  1. if/else basics
  2. switch — exhaustiveness, ranges, tuples, where
  3. Loops — for-in, while, repeat-while
← Back to Swift Academy