Menu: Difference between revisions
Content added Content deleted
(Added zkl) |
(Add Nimrod) |
||
Line 1,120: | Line 1,120: | ||
fee fie |
fee fie |
||
</pre> |
</pre> |
||
=={{header|Nimrod}}== |
|||
{{trans|Python}} |
|||
<lang nimrod>import strutils, rdstdin |
|||
proc menu(xs) = |
|||
for i,x in xs: echo " ",i,") ",x |
|||
proc ok(reply, count): bool = |
|||
try: |
|||
let n = parseInt(reply) |
|||
return 0 <= n and n < count |
|||
except: return false |
|||
proc selector(xs, prompt): string = |
|||
if xs.len == 0: return "" |
|||
var reply = "-1" |
|||
while not ok(reply, xs.len): |
|||
menu(xs) |
|||
reply = readLineFromStdin(prompt).strip() |
|||
return xs[parseInt(reply)] |
|||
const xs = ["fee fie", "huff and puff", "mirror mirror", "tick tock"] |
|||
let item = selector(xs, "Which is from the three pigs: ") |
|||
echo "You chose: ", item</lang> |
|||
Output: |
|||
<pre> 0) fee fie |
|||
1) huff and puff |
|||
2) mirror mirror |
|||
3) tick tock |
|||
Which is from the three pigs: foo |
|||
0) fee fie |
|||
1) huff and puff |
|||
2) mirror mirror |
|||
3) tick tock |
|||
Which is from the three pigs: 4 |
|||
0) fee fie |
|||
1) huff and puff |
|||
2) mirror mirror |
|||
3) tick tock |
|||
Which is from the three pigs: 2 |
|||
You chose: mirror mirror</pre> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |