Lua'end'预计(关闭'如果'在第11行)靠近'直到'

时间:2016-04-09 06:04:04

标签: lua

我正在使用的函数在运行时给出了'end' expected (to close 'if' at line 11) near 'until'错误,但我检查了整个程序中我没有错过'end'。另外,我没有使用return或其他类似命令(我知道)

function sell_item(item, soldfor)
  items_found = 0
  for i, v in pairs(inv) do
      if v == item then
          items_found = items_found + 1
      end
  end
  if items_found ~= 0 then
      items_destroyed = 0
      until items_destroyed == 1 do
          for i, v in pairs(inv) do
              if v == item then
                  pop_inv(item)
                  items_destroyed = 1
                  io.write(item .. " sold for " .. soldfor .. " coins")
                  count = 0
                  while count ~= soldfor do
                      table.insert(money, "coin")
                      count = count + 1
                  end
                  count = 0
              end
          end
          items_destroyed = 0
      end
  elseif items_found == 0 then
      io.write("You do not have this item")
  end
end

1 个答案:

答案 0 :(得分:2)

问题是repeat - untiluntil循环的后半部分,并且您在没有前面的重复语句的情况下编写了它。将while替换为while,它应该运行正常,因为您似乎想要在循环开始时使用测试循环,这是一个until循环。 ...\Agda-2.3.2.2\lib\prim\Agda\Primitive.agda循环在最后进行测试。