Menu: Difference between revisions

704 bytes added ,  3 years ago
(Added Commodore BASIC.)
Line 1,330:
 
=={{header|Icon}} and {{header|Unicon}}==
New version :
{{incorrect|Icon|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.]}}{{incorrect|Unicon|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].}}
Note the procedures below the "subroutines below" line are the actual
<lang Icon>procedure main()
Rosetta task set.
 
procedure main() shows how to call the choose_from_menu "function", which demonstrates use of differing menu lists and a empty list.
 
<lang Icon>
<lang Icon>procedure main()
L := ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
K := ["hidie hi", "hidie ho", "mirror mirror on the Wall", "tick tock tick tok"]
Z := []
choice := choose_from_menu(L) # call using menu L
write("Returned value =", choice)
choice := choose_from_menu(K) # call using menu K
write("Returned value =", choice)
choice := choose_from_menu(Z) # call using empty list
write("Returned value =", choice)
 
every i := 1 to *L do
end ## of main
write(i,") ",L[i])
# --------- subroutines below ---------------------------------
 
procedure
displaymenu(X)
repeat {
writes("Choose a number from the menu above: ")
a := read()
if 1a <== integer"" then return(a) <= i then## no breakselection
write("You selected ",a," ==> ",L[a])
if numeric(a) then {
if integer(a) <= 0 | integer(a) > *X then displaymenu(X) else
{ ## check entered option in range
write(ia, ") ==> ",LX[ia])
return ( string(a))
}
}
else displaymenu(X)
}
 
write("You selected ",a," ==> ",L[a])
end ## choose_from_menu(X)
end</lang>
 
procedure displaymenu(X)
every i := 1 to *LX do
write(i,") ",X[i]) ## display menu options
end ## displaymenu(X)
# ------------- end subroutines -----------------
 
 
 
end</lang>
 
=={{header|J}}==