Menu: Difference between revisions

1,042 bytes added ,  11 years ago
→‎{{header|REXX}}: added/changed comments, changed indentation, added DO-END comment labels, changed method of looping for user prompt, added an example of output. -- ~~~~
(Added BBC BASIC)
(→‎{{header|REXX}}: added/changed comments, changed indentation, added DO-END comment labels, changed method of looping for user prompt, added an example of output. -- ~~~~)
Line 1,223:
 
=={{header|REXX}}==
<lang rexx>/*REXX program shows a list, asks user for a selection number (integer).*/
<lang rexx>
 
/*REXX program shows a list, asks user for a selection number (integer).*/
ok=1 do forever /*assumekeep everythingasking isuntil peachyresponse OK. */
do forever
call list_create /*create the list from scratch. */
call list_show /*display (show) the list to user*/
if list.0#==0 then return '' /*if empty list, then return null*/
say right(' choose an item by entering a number from 1 --->───►' list.0#, 70, /*ask.*/'═')
parse pull x /*get the user's choice (if any).*/
 
ok=1 /*assume everything is peachy. */
select
if x='' then call sayErr "a choice wasn't entered"
if words( when x)\==1'' then call sayErr 'too"a manychoice choiceswasn't entered:'"
if \datatype when words(x,'N')\==1 then call sayErr "the'too choicemany isn'tchoices numericentered:"'
if when \datatype(x,'WN') then call sayErr "the choice isn't an integernumeric:"
if x<1 |when \datatype(x>list.0,'W') then call sayErr "the choice isn't withinan rangeinteger:"
if x='' when x<1 | x># then call sayErr "athe choice wasnisn't enteredwithin range:"
if ok then leave /*OK? Then we got a good choice.*/
otherwise leave /*this leaves the DO FOREVER loop*/
end
end /*select*/
doend /*forever*/
/*user might've entered 2. or 003*/
x=x/1 /*normalize the number (maybe). */
say; say 'you chose item' x": " list#.x
listreturn #.0=4 x /*storestick #a of choicesfork in list.0 it, we're done.*/
exit
/*──────────────────────────────────LIST_CREATE─────────────────────────*/
 
list_create: #.1='fee fie' /*there'reone method otherfor list-building methods. */
list #.2='huff and puff'
list.1='fee fie'
list #.3='mirror mirror'
list.2='huff and puff'
list #.4='tick tock'
list.3='mirror mirror'
#=4 /*store number of choices in #. */
list.4='tick tock'
list.0=4 /*store # of choices in list.0 */
return /*(above) is just one convention.*/
/*──────────────────────────────────LIST_SHOW───────────────────────────*/
 
list_show: say /*display a blank line. */
do j=1 for list.0 for # /*display the list of choices. */
say '([item' j")] " list#.j /*display item # with its choice.*/
end /*j*/
say /*display another blank line. */
return
/*──────────────────────────────────SAYERR──────────────────────────────*/
sayErr: if \ok then returnsay; ok=0; say;say '***error!***' arg(1) x; say;say; return</lang>
'''output''' (up to the point of the prompt):
<pre style="overflow:scroll">
list.[item 1='] fee fie'
[item 2] huff and puff
[item 3] mirror mirror
[item 4] tick tock
 
════════════════════ choose an item by entering a number from 1 ───► 4
sayErr: if \ok then return; ok=0; say;say '***error!***' arg(1) x;say;say;return
</langpre>
 
=={{header|REBOL}}==