Menu: Difference between revisions

Content added Content deleted
(added Fantom example)
(Go solution)
Line 447: Line 447:


=={{header|Fantom}}==
=={{header|Fantom}}==
<lang fantom>class Main

<lang fantom>
class Main
{
{
static Void displayList (Str[] items)
static Void displayList (Str[] items)
Line 484: Line 482:
echo ("You chose: $choice")
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}}==
=={{header|Haskell}}==