What does this print?
func greet(
_ name: String,
times: Int = 1
) {
for _ in 0..<times {
print("Hi \(name)")
}
}
greet("Alice")
greet("Bob", times: 2)
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
Hi Alice Hi Bob Hi Bob
Explanation:
Default parameters provide fallback values when arguments are omitted.
[/spoiler]