Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
36
Task/Menu/Swift/menu.swift
Normal file
36
Task/Menu/Swift/menu.swift
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
func getMenuInput(selections: [String]) -> String {
|
||||
guard !selections.isEmpty else {
|
||||
return ""
|
||||
}
|
||||
|
||||
func printMenu() {
|
||||
for (i, str) in selections.enumerated() {
|
||||
print("\(i + 1)) \(str)")
|
||||
}
|
||||
|
||||
print("Selection: ", terminator: "")
|
||||
}
|
||||
|
||||
while true {
|
||||
printMenu()
|
||||
|
||||
guard let input = readLine(strippingNewline: true), !input.isEmpty else {
|
||||
return ""
|
||||
}
|
||||
|
||||
guard let n = Int(input), n > 0, n <= selections.count else {
|
||||
continue
|
||||
}
|
||||
|
||||
return selections[n - 1]
|
||||
}
|
||||
}
|
||||
|
||||
let selected = getMenuInput(selections: [
|
||||
"fee fie",
|
||||
"huff and puff",
|
||||
"mirror mirror",
|
||||
"tick tock"
|
||||
])
|
||||
|
||||
print("You chose: \(selected)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue