如何重复留言

时间:2014-06-16 03:11:29

标签: lua

我制作代码只是为了测试一些东西

print('Hello! What is your name?')
name = io.read()
print('Hello '..name..'!')

repeat
    print('What does a mute person say?')
    say = io.read()
    x = 'Nothing'
    z = 'nothing'
    if say == x then
        print('Correct!')
    elseif say == z then
        print('Correct!')
    else
        print('Incorrect! Guess Again!')
    end
until say = x or z

我测试时一切正常,但如果答案不正确,你不能再试一次。可能是一个愚蠢的问题但是,无论如何,当答案不正确时,是否还要重复提问?

1 个答案:

答案 0 :(得分:1)

循环条件say = x or z不应该编译,使用==来测试相等性,而不是=

这还不够,say == x or z相当于say == x,因为如果x or z不是xx的值为nil }或false

repeat
    -- read say
until say == x or say == z