iOS ● ○ ○ Swift 6

Kodebits Day 93: Default Parameter

Sep 15 2026
Practice functions with a short swift challenge.

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]


Further Reading