3 min readJan 19, 2026
SwiftHow to Write If-Else Logic
Branch behavior with clear, readable conditions.
Steps
- Paste the code into a Swift file or playground.
- Run it once to verify the output.
- Adjust the inputs to match your use case.
Copy and paste
import Foundation
let score = 82
if score >= 90 {
print("A")
} else if score >= 80 {
print("B")
} else {
print("Keep going")
}Notes
- Keep functions small and focused for reuse.
- Prefer safe APIs like optionals and guards.
