Menu: Difference between revisions

1,401 bytes added ,  3 years ago
Added Commodore BASIC.
m (→‎{{header|Wren}}: Removed an unnecessary space.)
(Added Commodore BASIC.)
Line 247:
end function</lang>
 
 
==={{header|Commodore BASIC}}===
 
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.
 
<lang commodorebasic>1 rem menu
5 rem rosetta code
10 gosub 900
 
20 print chr$(147);chr$(14)
30 print " Menu "
35 print:print "Choose an incantation:":print
40 for i=1 to 5
45 print i;chr$(157);". ";op$(i,1)
50 next i:print
55 print "choose one: ";
60 get k$:if k$<"1" or k$>"5" then 60
65 k=val(k$):print chr$(147)
70 on k gosub 100,200,300,400,500
80 if k=5 then end
 
90 print:print "Press any key to continue."
95 get k$:if k$="" then 95
96 goto 20
 
100 rem fee fi
110 print op$(k,2)
115 return
 
200 rem huff puff
210 print op$(k,2)
215 return
 
300 rem mirror mirror
310 print op$(k,2)
315 return
 
400 rem tick tock
410 print op$(k,2)
415 return
 
500 rem quit
510 print op$(k,2):print "Goodbye!"
515 return
 
900 rem initialize
905 dim op$(10,2)
910 for a=1 to 5
915 read op$(a,1),op$(a,2)
920 next a
925 return
 
1000 data "Fee fi fo fum","I smell the blood of an Englishman!"
1005 data "Huff and puff","The house blew down!"
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."</lang>
 
=={{header|Batch File}}==
113

edits