这是给你的一个老式的 IF 语句,但是有一个问题
我在 QBASIC 中有一个 IF 语句...是的...QBASIC...
我一直在教某人编程(我认为这会很好并且很容易看到 语法如何工作)。
...无论如何,我有这样的代码:
CLS
start:
INPUT ">>", a$
PRINT a$
IF (INSTR(a$, "do you")) THEN
IF (INSTR(a$, "like")) THEN
IF (INSTR(a$, "cheese")) THEN PRINT "Yep, I like cheese":
IF (INSTR(a$, "music")) THEN PRINT "Depends, which genre?": GOTO musicGenre
ELSE IF (INSTR(a$, "hate")) THEN
IF (INSTR(a$, "cheese")) THEN PRINT "No, I like cheese"
END IF
END IF
END IF
musicGenre:
INPUT ">>", m$
SELECT CASE (m$)
CASE "pop"
PRINT "..pop! lol, baa baa"
CASE "rock"
PRINT "Rock is ok"
END SELECT
GOTO start
但是当我输入“你喜欢奶酪吗?
”时,它似乎只每隔一次回复“是的,我喜欢奶酪
” ...
有人能解释一下吗?
注意:
“你喜欢音乐吗?
”每次都有效...
注释 2:
输出截图:
I have an IF statement in QBASIC... yes... QBASIC...
I have been teaching someone to program (I decided this would be nice and easy to see
how the syntax works).
...Anyway, I have this code:
CLS
start:
INPUT ">>", a$
PRINT a$
IF (INSTR(a$, "do you")) THEN
IF (INSTR(a$, "like")) THEN
IF (INSTR(a$, "cheese")) THEN PRINT "Yep, I like cheese":
IF (INSTR(a$, "music")) THEN PRINT "Depends, which genre?": GOTO musicGenre
ELSE IF (INSTR(a$, "hate")) THEN
IF (INSTR(a$, "cheese")) THEN PRINT "No, I like cheese"
END IF
END IF
END IF
musicGenre:
INPUT ">>", m$
SELECT CASE (m$)
CASE "pop"
PRINT "..pop! lol, baa baa"
CASE "rock"
PRINT "Rock is ok"
END SELECT
GOTO start
But when I type "do you like cheese?
" it seems to only reply "Yep, I like cheese
" every other time...
Could anyone shed some light on this?
note:
"do you like music?
" works every time...
note 2:
Screenshot of the output:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您提供的代码看起来是正确的。
请尝试以下操作之一:
IF
之前输出输入 (a$
),以确认您的代码能够处理预期的输入。FALSE
为零,true 则为其他值。但是,您可能希望使用以下IF (INSTR(a$) > 0)
更加明确。编辑:您应该在任何奶酪结果上添加
goto start
。否则,它将转到musicGenre
代码。Your code you provided appears correct.
Try one of the following:
a$
) before the firstIF
to confirm your code will be working with the expected input.FALSE
is zero and true is anything else. However, you may want to be more explicit with the followingIF (INSTR(a$) > 0)
.EDIT: You should put a
goto start
on any cheese result. Otherwise, it's going to themusicGenre
code.该程序演示了在 Basic 中解析输入和 gosub。
This program demonstrates parsing input and gosubs in Basic.