使用整数变量比使用浮点变量更快。出于效率原因,您可以将k和op变量更改为k%和op%。
要在此菜单中进行现场直播,您有多种可能性。按照我个人喜好排序:
使用SELECT CASE
DO
CLS
... ' the instructions that build your menu
LOCATE 21, 15: INPUT "Enter your option"; op%
SELECT CASE op%
CASE 1
... ' instructions belonging to 1st option
CASE 2
... ' instructions belonging to 2nd option
CASE 3
... ' instructions belonging to 3rd option
CASE 4
... ' instructions belonging to 4th option
CASE 5
END
END SELECT
LOOP
使用IF
DO
CLS
... ' the instructions that build your menu
LOCATE 21, 15: INPUT "Enter your option"; op%
IF op%=1 THEN
... ' instructions belonging to 1st option
ELSEIF op%=2 THEN
... ' instructions belonging to 2nd option
ELSEIF op%=3 THEN
... ' instructions belonging to 3rd option
ELSEIF op%=4 THEN
... ' instructions belonging to 4th option
ELSEIF op%=5 THEN
END
END IF
LOOP
使用ON GOSUB
DO
CLS
... ' the instructions that build your menu
LOCATE 21, 15: INPUT "Enter your option"; op%
IF op%>0 AND op%<6 THEN
ON op% GOSUB one, two, three, four, five
ENDIF
LOOP
one: ... ' instructions belonging to 1st option
RETURN
two: ... ' instructions belonging to 2nd option
RETURN
three: ... ' instructions belonging to 3rd option
RETURN
four: ... ' instructions belonging to 4th option
RETURN
five: END
使DO ... LOOP
程序运行,直到用户最终按下5以选择Exit。任何无效的输入都会重新显示菜单。