if statements decide which code block to run based on a condition. They're essential for things like login success/fail, grading scores, user role permissions, and form validation.
swift
let score = 82
if score >= 90 {
print("Grade A")
} else if score >= 75 {
print("Grade B")
} else if score >= 60 {
print("Grade C")
} else {
print("Try again")
}Swift checks conditions from top to bottom. score >= 90 isn't true, so it moves on to check the next condition — score >= 75 — which is true, so it outputs Grade B.
You should see
Grade B