Menu: Difference between revisions

Content added Content deleted
(Added Delphi example)
(Added Wren)
Line 3,281: Line 3,281:
Which is from the three pigs: 2
Which is from the three pigs: 2
Output: huff and puff</pre>
Output: huff and puff</pre>

=={{header|Wren}}==
{{libheader|Wren-ioutil}}
<lang ecmascript>import "/ioutil" for Input

var menu = Fn.new { |list|
var n = list.count
if (n == 0 ) return ""
var prompt = "\n M E N U\n\n"
for (i in 0...n) prompt = prompt + "%(i+1). %(list[i])\n"
prompt = prompt + "\nEnter your choice (1 - %(n)): "
var index = Input.integer(prompt, 1, n)
return list[index-1]
}

var list = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
var choice = menu.call(list)
System.print("\nYou chose : %(choice)")</lang>

{{out}}
Sample run:
<pre>
M E N U

1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock

Enter your choice (1 - 4): 6
Must be an integer between 1 and 4, try again.

M E N U

1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock

Enter your choice (1 - 4): m
Must be an integer between 1 and 4, try again.

M E N U

1. fee fie
2. huff and puff
3. mirror mirror
4. tick tock

Enter your choice (1 - 4): 4

You chose : tick tock
</pre>


=={{header|XPL0}}==
=={{header|XPL0}}==