lua-users home
lua-l archive

Re: Help with sting compare?

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


On Aug 18, 2005, at 9:42 PM, Rici Lake wrote:
count = 0
for aline in io.lines() do
 if aline == "&" then count = count + 1
 elseif aline == "&&" then break
 end
end
print(count)
I tried replacing my io.read() with your io.lines() construct, but because the if statements are still not working for me mine is still not detecting the "&"
Here is my program as it currently stands:
#! /usr/local/bin/lua
-- Read fortunes in
do
 local aline
 jar = {}
 pointer = 0
 cookie = 1
 for aline in io.lines() do
 jar[cookie .. "+" .. pointer] = aline
 pointer = pointer + 1
print(">" .. string.sub(aline,1,2) .. "< " .. cookie .. " " .. pointer)
 if ( string.sub(aline,1,2) == "&&") then
 break
 end
 if ( string.sub(aline,1,1) == "&") then
 pointer = 0
 cookie = cookie + 1
 end
 end
 print(pointer .. " " .. cookie)
end
This incorporates your change, but cookie still increments for me, and pointer is never re-zeroed, In your example none of your if statements had a finishing end,
am I doing that wrong??
do I need to do
if (condition) then do
 statement
 statement
end
I am trying that with the code but it is confusing me....

AltStyle によって変換されたページ (->オリジナル) /