Lua 錯誤提示

2021-06-21 14:44:52 字數 720 閱讀 6679

1:

x = 10

local i = 1

while i<=x do

local x = i*2

print(x)

i = i + 1

end提示錯誤:stdin:1: attempt to compare nil with number 這是怎麼回事呀?

它的意思是你用數字跟nil值做了比較,自然得出了錯誤。

另外,你貼的**我執行了,是沒有問題的。

2. 區域性變數與**塊

* 區域性變數新增

local

來宣告,區域性變數只在宣告區域性變數的**塊內有效

* 在互動模式下區域性變數的作用域可能和想的會有所不同,因為一行執行是個完整的

chunk

> local i = 1

> print(i)

nil>

* 利用

do ... end

可以更好的定義語句塊,為乙個

chunk

劃分界限。

do ... end

相當於c

中 do

Lua錯誤摘要

lua連線資料庫時報以上錯誤,下面是執行的指令碼摘錄 local cjson require cjson local mysql require resty.mysql local db mysql new db set timeout 10000 local props local res db ...

python 提示錯誤 Python異常提示

一 在以前的 中已經看過異常。通常錯誤的 或輸入會引發異常。發生異常時,程式立即停止。下面的 通過嘗試將7除以0來產生 zerodivisionerror 異常。num1 7num2 0print num1 num2 顯示結果 zerodivisionerror division by zero 不...

python 提示錯誤 python錯誤筆記

1.print hello world syntaxerror missing parentheses in call to paint did you mean print hello world 在呼叫 paint 時缺少圓括號。上面的語法在python3中是錯誤的。在python3中,你需要將...