Anonymous user
Menu: Difference between revisions
→{{header|Icon}} and {{header|Unicon}}
(Added Commodore BASIC.) |
|||
Line 1,330:
=={{header|Icon}} and {{header|Unicon}}==
New version :
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>
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
if numeric(a) then {
if integer(a) <= 0 | integer(a) > *X then displaymenu(X) else
{ ## check entered option in range
return ( string(a))
}
}
else displaymenu(X)
}
▲write("You selected ",a," ==> ",L[a])
end ## choose_from_menu(X)
end</lang>▼
procedure displaymenu(X)
write(i,") ",X[i]) ## display menu options
end ## displaymenu(X)
# ------------- end subroutines -----------------
=={{header|J}}==
|