Menu: Difference between revisions

618 bytes added ,  13 years ago
Go solution
(added Fantom example)
(Go solution)
Line 447:
 
=={{header|Fantom}}==
<lang fantom>class Main
 
<lang fantom>
class Main
{
static Void displayList (Str[] items)
Line 484 ⟶ 482:
echo ("You chose: $choice")
}
}</lang>
=={{header|Go}}==
<lang go>package main
 
import "fmt"
 
var choices = []string{
"fee fie",
"huff and puff",
"mirror mirror",
"tick tock",
}
 
</lang>
func menu(choices []string) string {
if len(choices) == 0 {
return ""
}
var c int
for {
fmt.Println("")
for i, s := range choices {
fmt.Printf("%d. %s\n", i+1, s)
}
fmt.Print("Enter number: ")
_, err := fmt.Scanln(&c)
 
if err == nil && c > 0 && c <= len(choices) {
break
}
}
return choices[c-1]
}
 
func main() {
fmt.Println(menu(choices))
}</lang>
 
=={{header|Haskell}}==
1,707

edits