Menu: Difference between revisions

749 bytes added ,  8 years ago
m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, added a note within the output to signify what the user entered.
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, added a note within the output to signify what the user entered.)
Line 1,841:
 
=={{header|REXX}}==
<lang rexx>/*REXX program showsdisplays a list, asks then prompts the user for a selection number (integer).*/
do forever /*keep askingprompting until response is OK. */
x=x/1 call list_create /*normalizecreate the numberlist (maybe)from scratch. */
call list_show /*display (show) /*userthe might'velist enteredto 2the user. or 003*/
if #==0 then return '' /*if list is empty, then return null.*/
say right(' choose an item by entering a number from 1 ───►' #, 70, '═')
parse pull x /*get the user's choice (if any). */
 
end /* select*/
do forever /*keep asking until response OK. */
call list_create when x='' /*create the list from scratch. then call sayErr "a choice wasn't */entered"
call list_show when words(x)\==1 then call sayErr 'too /*display (show) the listmany tochoices user*/entered:'
if #==0 then return '' when \datatype(x,'N') then call sayErr /*if"the emptychoice list, then returnisn't null*/numeric:"
when \datatype(x,'W') then call sayErr "the choice isn't an integer:"
say right(' choose an item by entering a number from 1 ───►' #, 70, '═')
parse pull x when x<1 | x># then call sayErr /*get "the user's choice (ifisn't within any).*/range:"
otherwise leave /*this leaves the DO FOREVER loop.*/
 
end /*select*/
when x='' end then call sayErr "a choice wasn't entered"/*forever*/
/*user might've entered 2. or 003 */
when words(x)\==1 then call sayErr 'too many choices entered:'
x=x/1 /*normalize the number (maybe). */
when \datatype(x,'N') then call sayErr "the choice isn't numeric:"
when \datatype(x,'W') then call sayErr "the choice isn't an integer:"
when x<1 | x># then call sayErr "the choice isn't within range:"
otherwise leave /*this leaves the DO FOREVER loop*/
end /*select*/
end /*forever*/
/*user might've entered 2. or 003*/
x=x/1 /*normalize the number (maybe). */
say; say 'you chose item' x": " #.x
return #.x /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────LIST_CREATE─────────────────────────*/
list_create: #.1= 'fee fie' /*this is one method for list-building. */
#.2= 'huff and puff'
#.3= 'mirror mirror'
#.4= 'tick tock'
#=4 #=4 /*store the number of choices in #. */
return return /*(above) is just one convention. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────LIST_SHOW───────────────────────────*/
list_show: say /*display a blank line. */
do j=1 for # /*display the list of choices. */
say '[item' j"] " #.j /*display item #number with its choice. */
end /*j*/
say say /*display another blank line. */
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────SAYERR──────────────────────────────*/
sayErr: say; say '***error!***' arg(1) x; say; return</lang>
'''output''' &nbsp; (upwhich toincludes what the point of theuser prompt)entered:
<pre>
<pre style="overflow:scroll">
[item 1] fee fie
[item 2] huff and puff
Line 1,887 ⟶ 1,886:
 
════════════════════ choose an item by entering a number from 1 ───► 4
2 ◄■■■■■■■■■■■■■■■■■■■■■■ what the user entered at the terminal.
 
you chose item 2: huff and puff
</pre>