Jump to content

Menu: Difference between revisions

641 bytes added ,  12 years ago
→‎{{header|Perl 6}}: Add Perl 6 example
(→‎{{header|Perl 6}}: Add Perl 6 example)
Line 862:
 
print "You chose: $a\n";</lang>
 
=={{header|Perl 6}}==
<lang perl6>sub menu ( $prompt, @items ) {
return '' unless @items.elems;
my $selection = '';
repeat until $selection ~~ /^ \d+ $/ && @items[--$selection].so
{
my $i = 1;
say " {$i++}) $_" for @items;
$selection = prompt $prompt;
}
return @items[$selection];
}
 
my @choices = ('fee fie', 'huff and puff', 'mirror mirror', 'tick tock');
my $prompt = 'Enter the number corresponding to your selection: ';
 
my $answer = menu( $prompt, [] );
say "You chose: $answer" if $answer.chars;
 
$answer = menu( $prompt, @choices );
say "You chose: $answer" if $answer.chars;</lang>
 
=={{header|PL/I}}==
10,351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.