Lua elseif not working properly

前端 未结 1 1465
没有蜡笔的小新
没有蜡笔的小新 2021-01-20 18:07

When I attempt to use elseif, it doesn\'t work. In the case of the code below, no matter which number the user inputs, the only code that runs is the code under

相关标签:
1条回答
  • 2021-01-20 18:50

    The problem is not with the elseif. The problem is because io.read() returns a string. Either convert it to a number:

    pref = tonumber(io.read())
    

    Or, compare pref with "1", "2" instead.

    0 讨论(0)
提交回复
热议问题