Menu: Difference between revisions
m
syntax highlighting fixup automation
(Applesoft BASIC) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 21:
=={{header|11l}}==
<
L
Line 33:
I Int(reply) C 1..items.len
print(‘You chose: ’items[Int(reply) - 1])
L.break</
{{out}}
Line 56:
=={{header|Action!}}==
<
BYTE FUNC Init(PTR ARRAY items)
Line 92:
res=GetMenuItem(items,count)
PrintF("You have chosen: %S%E",items(res))
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Menu.png Screenshot from Atari 8-bit computer]
Line 112:
=={{header|Ada}}==
<
procedure menu is
Line 138:
put_line ("You chose " &
choice ((+"fee fie",+"huff and puff",+"mirror mirror",+"tick tock"),"Enter your choice "));
end menu;</
=={{header|ALGOL 68}}==
Line 147:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''}}
<
(
INT choice;
Line 174:
printf(($"You chose "g"."l$, menu select(items, prompt)))
)</
Output:
<pre>
Line 186:
=={{header|Arturo}}==
<
selection: neg 1
while [not? in? selection 1..size items][
Line 197:
]
menu ["fee fie" "huff and puff" "mirror mirror" "tick tock"]</
{{out}}
Line 219:
=={{header|AutoHotkey}}==
<
if !list ; if called with an empty list
return ; return an empty string
Line 228:
InputBox , Choice, Please Select From Menu, % string ,, % 200<len*7 ? 200 ? len*7 , % 120 + x.count()*20
return x[Choice]
}</
Examples:<
(
fee fie
Line 238:
MsgBox % Menu(list) ; call menu with list
MsgBox % Menu() ; call menu with empty list
return</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f MENU.AWK
BEGIN {
Line 267:
}
}
</syntaxhighlight>
=={{header|Axe}}==
{{incorrect|Axe|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
In Axe, static data (such as strings) is laid out sequentially in memory. So the H in "HUFF" is the byte after the null terminator for "FIE". However, null terminators are only added to strings when they are stored with the store symbol →. strGet returns a pointer to the start of the nth null-terminated string in the data, which is why the strings must be laid out in memory correctly.
<
"HUFF AND PUFF"→Str2
"MIRROR MIRROR"→Str3
Line 286:
Return
End
Disp strGet(Str1,N-1),i</
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
<
if ubound(choices$) - lbound(choices$) = 0 then sel$ = ""
ret$ = ""
Line 301:
while ret$ = ""
sel$ = ret$
end function</
==={{header|Applesoft BASIC}}===
While the following example could be lengthened to demonstrate larger menu-driven projects, it is useful to simply print the resulting string indexed by the user input.
<
20 M$(3) = "MIRROR MIRROR"
30 M$(2) = "HUFF AND PUFF"
Line 322:
170 NEXT M
180 M$ = M$(N%)
190 RETURN </
==={{header|Commodore BASIC}}===
Line 328:
While the following example could be shortened to simply print the resulting string indexed by the user input, it is useful to demonstrate that larger menu-driven projects benefit from the use of the <code>ON n... GOSUB</code> statement to pass control to larger subroutines.
<
5 rem rosetta code
10 gosub 900
Line 379:
1010 data "Mirror, mirror","You seem to be the fairest of them all!"
1015 data "Tick tock","Time passes..."
1020 data "<Quit>","You decide to leave."</
=={{header|Batch File}}==
Example 1
<
set "menuChoices="fee fie","huff and puff","mirror mirror","tick tock""
Line 412:
echo.Invalid Input. Please try again...
pause
goto :tryagain</
Example 2
<
@echo off
Line 441:
echo.!string[%choice%]!
goto:eof
</syntaxhighlight>
=={{header|BBC BASIC}}==
<
list$() = "fee fie", "huff and puff", "mirror mirror", "tick tock"
selected$ = FNmenu(list$(), "Please make a selection: ")
Line 464:
IF index%>=0 IF index%<=DIM(list$() ,1) IF list$(index%)="" index% = -1
UNTIL index%>=0 AND index%<=DIM(list$(), 1)
= list$(index%)</
Empty entries in the list are not offered as options, nor accepted as a selection.
=={{header|Brat}}==
<
true? choices.empty?
{ "" }
Line 488:
}
p menu "Selection: " ["fee fie" "huff and puff" "mirror mirror" "tick tock"]</
=={{header|C}}==
<
#include <stdlib.h>
#include <string.h>
Line 534:
return items[choice - 1];
}</
=={{header|C sharp}}==
<
using System;
using System.Collections.Generic;
Line 569:
}
}
</syntaxhighlight>
=={{header|C++}}==
<
#include <string>
#include <vector>
Line 621:
std::cout << "You chose: " << data_entry("> ", terms) << std::endl;
}
</syntaxhighlight>
=={{header|Ceylon}}==
<
shared void run() {
value selection = menu("fee fie", "huff And puff", "mirror mirror", "tick tock");
Line 647:
}
</syntaxhighlight>
=={{header|Clojure}}==
<
(if (empty? choices)
""
Line 671:
(println "You chose: "
(menu "Which is from the three pigs: "
["fee fie" "huff and puff" "mirror mirror" "tick tock"]))</
=={{header|COBOL}}==
<
PROGRAM-ID. Test-Prompt-Menu.
Line 765:
.
END PROGRAM Prompt-Menu.</
=={{header|Common Lisp}}==
<
(if (null choices)
""
Line 780:
(force-output)
(setf n (parse-integer (read-line *standard-input* nil)
:junk-allowed t)))))</
=={{header|D}}==
<
string menuSelect(in string[] entries) {
Line 817:
"mirror mirror", "tick tock"];
writeln("You chose '", items.menuSelect, "'.");
}</
{{out}}
<pre>Choose one:
Line 829:
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Menu;
Line 859:
'tick tock'], 'Enter number: '));
readln;
end.</
{{out}}
<pre>
Line 878:
=={{header|Elixir}}==
<
def select(_, []), do: ""
def select(prompt, items) do
Line 898:
items = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
response = Menu.select("Which is from the three pigs", items)
IO.puts "you chose: #{inspect response}"</
{{out}}
Line 919:
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
PROCEDURE Selection(choices$[],prompt$->sel$)
IF UBOUND(choices$,1)-LBOUND(choices$,1)=0 THEN
Line 936:
sel$=ret$
END PROCEDURE
</syntaxhighlight>
=={{header|Euphoria}}==
<
function menu_select(sequence items, object prompt)
Line 960:
constant prompt = "Which is from the three pigs? "
printf(1,"You chose %s.\n",{menu_select(items,prompt)})</
=={{header|F Sharp|F#}}==
<
let rec menuChoice (options : string list) prompt =
Line 984:
printfn "You chose: %s" choice
0</
=={{header|Factor}}==
<
: print-menu ( seq -- )
Line 999:
] [ drop (select) ] if* ;
: select ( seq -- result ) [ "" ] [ (select) ] if-empty ;</
Example usage:
Line 1,014:
=={{header|Fantom}}==
{{incorrect|Fantom|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<
{
static Void displayList (Str[] items)
Line 1,049:
echo ("You chose: $choice")
}
}</
=={{header|Forth}}==
===Idiomatic Forth===
Out of the box Forth does not have lists. This version uses strings and a vector table, which arguably is more how one would do this task in Forth. It returns a nil string if a nil string is given otherwise the input string becomes the title of the menu.
<
\ vector table compiler
Line 1,095:
CR [CHAR] 0 - SELECT
THEN
;</
===If there must be lists===
Here we extend Forth to support simple lists and complete the task using the language extensions.
<
: STRING, ( caddr len -- ) HERE OVER CHAR+ ALLOT PLACE ;
Line 1,162:
CR SWAP {NTH}
THEN
;</
Test at the gForth console
Line 1,193:
Please find the build instructions in the comments at the start of the FORTRAN 2008 source. Compiler: gfortran from the GNU compiler collection. Command interpreter: bash.
<syntaxhighlight lang="fortran">
!a=./f && make $a && OMP_NUM_THREADS=2 $a
!gfortran -std=f2008 -Wall -fopenmp -ffree-form -fall-intrinsics -fimplicit-none f.f08 -o f
Line 1,251:
end program menu_demo
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
function menu_select( m() as string ) as string
Line 1,272:
end function
print menu_select( menu() )</
=={{header|Gambas}}==
<
Public Sub Main()
Line 1,326:
End
</syntaxhighlight>
=={{header|Go}}==
<
import "fmt"
Line 1,365:
pick = menu(choices, "Enter number: ")
fmt.Printf("You picked %q\n", pick)
}</
Output:
<pre>
Line 1,379:
=={{header|GW-BASIC}}==
<
10 DATA "Fee fie", "Huff and Puff", "Mirror mirror", "Tick tock"
20 VC = 0
Line 1,396:
150 PRINT "You picked ", M$(VC-1)
160 END
</syntaxhighlight>
=={{header|Haskell}}==
<
import Data.Maybe (listToMaybe)
Line 1,422:
maybeRead :: Read a => String -> Maybe a
maybeRead = fmap fst . listToMaybe . filter (null . snd) . reads</
Example usage, at the GHCI prompt:
<
1) fee fie
2) huff and puff
Line 1,432:
Choose an item: 3
"mirror mirror"
*RosettaSelect></
=={{header|HicEst}}==
{{incorrect|HicEst|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<
POP(Menu=list, SelTxt=answer)
Line 1,444:
! The global variable $$ returns the selected list index
WRITE(Messagebox, Name) answer, $$
END</
=={{header|Icon}} and {{header|Unicon}}==
Line 1,453:
procedure main() shows how to call the choose_from_menu "function", which demonstrates use of differing menu lists and a empty list.
<syntaxhighlight lang="icon">
## menu.icn : rewrite of the faulty version on Rosetta Code site 24/4/2021
Line 1,500:
end ## displaymenu(X)
</syntaxhighlight>
=={{header|J}}==
'''Solution:'''
<syntaxhighlight lang="j">
CHOICES =: ];._2 'fee fie;huff and puff;mirror mirror;tick tock;'
PROMPT =: 'Which is from the three pigs? '
Line 1,524:
RESULT {:: CHOICES
)
</syntaxhighlight>
See [[Talk:Select#J_implementation|Talk page]] for explanation.
=={{header|Java}}==
<
if(list.size() == 0) return "";
Scanner sc = new Scanner(System.in);
Line 1,544:
}while(ret == null);
return ret;
}</
=={{header|JavaScript}}==
{{works with|Node.js}}
<
async function menuSelect(question, choices) {
Line 1,583:
menuSelect(question, choices).then((answer) => {
console.log(`\nYou chose ${answer}`);
});</
=={{header|jq}}==
{{works with|jq|1.5}}
This version uses jq 1.5's 'input' builtin to read programmatically from STDIN.
<
def read(prompt; max):
def __read__:
Line 1,606:
| if ($read|type) == "string" then $read
else "Thank you for selecting \($in[$read-1])" end
end ;</
'''Example:'''
<
<syntaxhighlight lang="sh">
$ jq -n -r -f Menu.jq
Enter your choice:
Line 1,625:
1
Thank you for selecting fee fie</
=={{header|Julia}}==
{{trans|Python}}
<
function _menu(items)
Line 1,659:
items = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
item = _selector(items, "Which is from the three pigs: ")
println("You chose: ", item)</
=={{header|Kotlin}}==
<
fun menu(list: List<String>): String {
Line 1,686:
val choice = menu(list)
println("\nYou chose : $choice")
}</
Sample session:
{{out}}
Line 1,722:
=={{header|langur}}==
{{works with|langur|0.7.1}}
<
if not isArray(.entries): throw "invalid args"
if len(.entries) == 0: return ZLS
Line 1,742:
}
writeln .select(["fee fie", "eat pi", "huff and puff", "tick tock"])</
{{out}}
Line 1,757:
{{incorrect|Logo|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
{{works with|UCB Logo}}
<
foreach :options [(print # ?)]
forever [
Line 1,770:
[Which is from the three pigs?]
[fee fie] [huff and puff] [mirror mirror] [tick tock])
</syntaxhighlight>
=={{header|Lua}}==
<
if not list or #list == 0 then
return ""
Line 1,790:
print("Nothing:", select {})
print()
print("You chose:", select {"fee fie", "huff and puff", "mirror mirror", "tick tock"})</
{{out}}
Line 1,829:
Redisplays the list of choices on every invalid input as per the task description. In the notebook interface (of Wolfram Desktop, at least), Print[] would most pragmatically be located outside of the loop because Input[] uses a dialog box.
<
If[Length@data == 0, Return@""];
While[!(IntegerQ@choice && Length@data >= choice > 0),
Line 1,836:
];
data[[choice]]
]</
{{out|Kernel (REPL) output|note=function definition omitted}}
<pre>Wolfram Desktop Kernel (using Wolfram Language 12.0.0) for Microsoft Windows (64-bit)
Line 1,877:
=={{header|MATLAB}}==
<
if numel(list) == 0
Line 1,915:
end
</syntaxhighlight>
=={{header|min}}==
{{works with|min|0.19.3}}
min has an operator <code>choose</code> that nearly conforms to this task. The input list is altered so that the choice can be returned, and the empty list case is handled.
<
:prompt =list
(list bool)
Line 1,929:
("fee fie" "huff and puff" "mirror mirror" "tick tock")
"Enter an option" menu
"You chose: " print! puts!</
{{out}}
<pre>
Line 1,949:
=={{header|Modula-2}}==
{{incorrect|Modula-2|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<
FROM InOut IMPORT WriteString, WriteCard, WriteLn, ReadCard;
Line 1,986:
WriteLn;
END (*of IF*)
END Menu.</
=={{header|MUMPS}}==
<
;http://rosettacode.org/wiki/Menu
NEW I,A,MAX
Line 2,003:
IF (A<1)!(A>MAX)!(A\1'=A) GOTO WRITEMENU
KILL I,MAX
QUIT $PIECE(STRINGS,SEP,A)</
Usage:<pre>
USER>W !,$$MENU^ROSETTA("fee fie^huff and puff^mirror mirror^tick tock","^")
Line 2,045:
=={{header|Nanoquery}}==
{{trans|Ursa}}
<
for ($i = 0) ($i < len($items)) ($i = $i + 1)
println " " + $i + ") " + $items[$i]
Line 2,078:
append $items "fee fie" "huff and puff" "mirror mirror" "tick tock"
$item = selector($items, "Which is from the three pigs: ")
println "You chose: " + $item</
=={{header|Nim}}==
{{trans|Python}}
<
proc menu(xs: openArray[string]) =
Line 2,103:
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</
{{out}}
Line 2,124:
=={{header|OCaml}}==
<
let select ?(prompt="Choice? ") = function
| [] -> ""
Line 2,134:
with _ -> menu ()
in menu ()
</syntaxhighlight>
Example use in the REPL:
<
# select ["fee fie"; "huff and puff"; "mirror mirror"; "tick tock"];;
0: fee fie
Line 2,145:
Choice? 2
- : string = "mirror mirror"
</syntaxhighlight>
=={{header|OpenEdge/Progress}}==
<
i_c AS CHAR
):
Line 2,197:
MESSAGE
bashMenu( "fee fie,huff and puff,mirror mirror,tick tock" )
VIEW-AS ALERT-BOX.</
=={{header|Oz}}==
<
fun {Select Prompt Items}
case Items of nil then ""
Line 2,230:
in
{System.showInfo "You chose: "#Item}</
=={{header|PARI/GP}}==
{{incorrect|PARI/GP|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<
choose(["fee fie","huff and puff","mirror mirror","tick tock"])</
=={{header|Pascal}}==
{{works with|Free_Pascal}}
Tested with Free Pascal 2.6.4 (arm).
<
{$ASSERTIONS ON}
uses
Line 2,300:
dispose(MenuItems, Done);
end.</
{{out}}
Line 2,324:
=={{header|Perl}}==
<
{
my ($prompt,@array) = @_;
Line 2,341:
$a = &menu($prompt,@a);
print "You chose: $a\n";</
=={{header|Phix}}==
<
sequence res = ""
items = remove_all("",items)
Line 2,370:
constant prompt = "Which is from the three pigs? "
string res = menu_select(items,prompt)
printf(1,"You chose %s.\n",{res})</
=={{header|PHP}}==
<
$stdin = fopen("php://stdin", "r");
$allowed = array(1 => 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock');
Line 2,387:
break;
}
}</
=={{header|PicoLisp}}==
<
(use N
(loop
Line 2,400:
(T (>= (length Items) N 1) (prinl (get Items N))) ) ) )
(choose "Which is from the three pigs?"
'("fee fie" "huff and puff" "mirror mirror" "tick tock") )</
{{out}}
<pre>
Line 2,423:
=={{header|PL/I}}==
{{incorrect|PL/I|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<syntaxhighlight lang="pl/i">
test: proc options (main);
Line 2,442:
end test;
</syntaxhighlight>
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
function Select-TextItem
{
Line 2,523:
“fee fie”, “huff and puff”, “mirror mirror”, “tick tock” | Select-TextItem -Prompt "Select a string"
</syntaxhighlight>
{{Out}}
Line 2,538:
=={{header|ProDOS}}==
{{incorrect|ProDOS|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<syntaxhighlight lang="text">
:a
printline ==========MENU==========
Line 2,552:
printline You either chose an invalid choice or didn't chose.
editvar /newvar /value=goback /userinput=1 /title=Do you want to chose something else?
if -goback- /hasvalue y goto :a else exitcurrentprogram 1 </
=={{header|Prolog}}==
{{works with|SWI-Prolog|6}}
<
rosetta_menu([], "") :- !. %% Incase of an empty list.
rosetta_menu(Items, SelectedItem) :-
Line 2,574:
prompt1('Select a menu item by number:'),
read(Choice).
</syntaxhighlight>
Example run:
<
?- rosetta_menu(["fee fie", "huff and puff", "mirror mirror", "tick tock"], String).
Line 2,599:
Select a menu item by number:3.
String = "mirror mirror".
</syntaxhighlight>
=={{header|PureBasic}}==
<
Define i, txt$, choice
Dim txts.s(4)
Line 2,628:
TheStrings:
Data.s "fee fie", "huff And puff", "mirror mirror", "tick tock"
EndDataSection</
=={{header|Python}}==
<
for indexitem in enumerate(items):
print (" %2i) %s" % indexitem)
Line 2,657:
items = ['fee fie', 'huff and puff', 'mirror mirror', 'tick tock']
item = selector(items, 'Which is from the three pigs: ')
print ("You chose: " + item)</
Sample runs:
Line 2,688:
Uses [http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/base/html/menu.html menu].
<
{
if (is.null(choices)) return("")
Line 2,697:
str <- showmenu(c("fee fie", "huff and puff", "mirror mirror", "tick tock"))
str <- showmenu()
</syntaxhighlight>
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
Line 2,715:
(menu '("fee fie" "huff and puff" "mirror mirror" "tick tock"))
</syntaxhighlight>
Sample Run:
Line 2,744:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
return '' unless @items.elems;
repeat until my $selection ~~ /^ \d+ $/ && @items[--$selection] {
Line 2,761:
$answer = menu( $prompt, @choices );
say "You chose: $answer" if $answer.chars;</
=={{header|REBOL}}==
{{incorrect|REBOL|The function should return an empty string if called with an empty list. Please also check if this could really used as a [https://en.wikipedia.org/wiki/Subroutine function aka subroutine.]}}
<
Title: "Text Menu"
URL: http://rosettacode.org/wiki/Select
Line 2,785:
choice: ask "Which is from the three pigs? "
]
print ["You chose:" pick choices to-integer choice]</
Output:
Line 2,806:
You chose: huff and puff</pre>
=={{header|Red}}==
<
menu: function [items][
Line 2,813:
attempt [pick items to-integer ask "Your choice: "]
]]
]</
{{out}}
Line 2,839:
=={{header|REXX}}==
<
do forever /*keep prompting until response is OK. */
call list_create /*create the list from scratch. */
Line 2,875:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
sayErr: say; say '***error***' arg(1) x; say; return</
{{out|output|text= (which includes what the user entered):}}
<pre>
Line 2,890:
=={{header|Ring}}==
<
aList = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
selected = menu(aList, "please make a selection: ")
Line 2,910:
end
return aList[index]
</syntaxhighlight>
Output:
<pre>
Line 2,928:
=={{header|Ruby}}==
<
def select(prompt, items = [])
if items.empty?
Line 2,955:
response = select('Which is from the three pigs', items)
puts "you chose: >#{response}<"
</syntaxhighlight>
=={{header|Run BASIC}}==
<
choose$(1) = "1 Fee Fie"
choose$(2) = "2 Huff Puff"
Line 2,988:
cls
end
end if</
=={{header|Rust}}==
<
fn menu_select<'a>(items: &'a [&'a str]) -> &'a str {
if items.len() == 0 {
Line 3,039:
println!("You chose: {}", selection);
}
</syntaxhighlight>
=={{header|Scala}}==
===Scala idiom (Functional)===
<syntaxhighlight lang="text">import scala.util.Try
object Menu extends App {
Line 3,070:
println(s"\nYou chose : $choice")
}</
=={{header|Seed7}}==
<
const func string: menuSelect (in array string: items, in string: prompt) is func
Line 3,101:
begin
writeln("You chose " <& menuSelect(items, prompt));
end func;</
=={{header|Sidef}}==
<
arr.len > 0 || return ''
loop {
Line 3,120:
var answer = menu(prompt, list)
say "You choose: #{answer}"</
=={{header|Swift}}==
<
guard !selections.isEmpty else {
return ""
Line 3,159:
])
print("You chose: \(selected)")</
=={{header|Tcl}}==
<
set nc [llength $choices]
if {!$nc} {
Line 3,181:
}
}
}</
Testing it out interactively...
<
><
% puts >[select "Which is from the three pigs" {
Line 3,213:
4: tick tock
Which is from the three pigs: 2
>huff and puff<</
=={{header|TI-83 BASIC}}==
Line 3,244:
Output with <tt>FEE FIE:HUFF AND PUFF:MIRROR MIRROR:TICK TOCK</tt>
<syntaxhighlight lang="text"> 1:FEE FIE
2:HUFF AND PUFF
3:MIRROR MIRROR
4:TICK TOCK
? [flashing cursor]</
Line 3,270:
=={{header|True BASIC}}==
<
MAT READ menu$
DATA "fee fie", "huff and puff", "mirror mirror", "tick tock"
Line 3,289:
PRINT sel$(menu$())
END</
=={{header|UNIX Shell}}==
Line 3,303:
{{works with|pdksh}}
{{works with|zsh}}
<
# Prints menu to standard error. Prompts with PS3.
# Reads REPLY from standard input. Sets CHOICE.
Line 3,321:
choose 'fee fie' 'huff and puff' 'mirror mirror' 'tick tock'
[[ -n $CHOICE ]] && echo You chose: $CHOICE
[[ -z $CHOICE ]] && echo No input.</
<pre>$ bash menu.sh
Line 3,345:
* ''Deviation from task:'' When the list of choices is empty, this function returns an empty list, not an empty string.
<
# Prints menu to standard error. Prompts with $prompt.
# Returns choice. If no input, returns empty list.
Line 3,398:
~ $#choice 1 && echo You chose: $choice
~ $#choice 0 && echo No input.
}</
<pre>$ es menu.es
Line 3,410:
=={{header|Ursa}}==
{{trans|Python}}
<
for (decl int i) (< i (size items)) (inc i)
out " " i ") " items<i> endl console
Line 3,446:
decl string item
set item (selector items "Which is from the three pigs: ")
out "You chose: " item endl console</
=={{header|VBScript}}==
<
Function Menu(ArrList, Prompt)
Select Case False 'Non-standard usage hahaha
Line 3,484:
Sample = Array("fee fie", "huff and puff", "mirror mirror", "tick tock")
InputText = "Which is from the three pigs: "
WScript.StdOut.WriteLine("Output: " & Menu(Sample, InputText))</
{{Out}}
<pre>C:\>cscript /nologo menu.vbs
Line 3,520:
=={{header|Wren}}==
{{libheader|Wren-ioutil}}
<
var menu = Fn.new { |list|
Line 3,534:
var list = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
var choice = menu.call(list)
System.print("\nYou chose : %(choice)")</
{{out}}
Line 3,572:
=={{header|XPL0}}==
<
func Menu(List);
Line 3,593:
Text(0, Menu([5, "fee fie", "huff and puff", "mirror mirror", "tick tock",
"Which phrase is from the Three Little Pigs? "]))</
Example output:
Line 3,608:
=={{header|Yabasic}}==
<
// by Jjuanhdez, 06/2022
Line 3,646:
label menudata
data "Ack, not good", "fee fie ", "huff and puff"
data "mirror mirror", "tick tock ", "exit "</
=={{header|zkl}}==
<
os:=T("exit").extend(vm.arglist); N:=os.len();
if(N==1) return("");
Line 3,662:
teleprompter("fee fie" , "huff and puff" , "mirror mirror" , "tick tock")
.println();</
{{out}}
<pre>
|