lua-users home
lua-l archive

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


Hi,
I recently had a loop where I had to read a value that looped like this:

while true do
  local line = readline()
  if not line then break end
 ...
end

I know that there are ways how to write this in a nicer way (i.e.
having an iterator function), but wouldn't it be more nice if this
would work as well this way:

while true do
  local line = readline() or break
 ...
end

I think it would break some relationship to have a language feature
like that - however it simply looks so much nicer... Of course this
concept could be used in a coroutine environment, i.e. having a "stop"
function that yields the coroutine, i.e.

while true do
  local line = readline() or stop()
 ...
end

which looks already quite nice...

cheers,
Eike