[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: how io.read() will return nil ?
- From: "Jeff Pohlmeyer" <yetanothergeek@...>
- Date: Sun, 24 Aug 2008 05:36:14 -0500
On Sun, Aug 24, 2008 at 5:19 AM, lee <firstname.lastname@example.org> 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")
> 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")