Skip to content
Justice Tech School

Swift If and Else

Conditions need no parentheses but braces are required. Add else if and else for more branches. The ternary operator is cond ? a : b.

Example
let score = 72
if score >= 85 { print("Distinction") }
else if score >= 70 { print("Pass") }
else { print("Retake") }
print(score >= 50 ? "ok" : "low")

Exercise

Second branch.

if a {}  if b {}

Quiz Test

Are braces required?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.