lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Aug 24, 2008 at 5:19 AM, lee <leeyacn@126.com> wrote:
> hi, list
> I am a newbie to Lua and learning.
Welcome to Lua!

> I write a test script, named test3.lua:
>
>  for count = 1, math.huge do
>     local line = io.read()
>     if line == nil then break end
>     io.write(string.format("%6d ", count), line, "\n")
>  end
>
> The script is very simple, but after running it, I do not know how to exit
> the script normally.
> I means what I should input will make io.read() return nil.


I think you want to test for empty string, that is not the same as nil.
Try this one:

for count = 1, math.huge do
    local line = io.read()
    if #line == 0 then break end
    io.write(string.format("%6d ", count), line, "\n")
end


Regards,
- Jeff