lua-users home
lua-l archive

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



On 28 Feb 2008, at 13:35, Mark Hamburg wrote:
Nothing. But sometimes one wants more logic which gets in the way of the if.
For example:

    while true do repeat

        if processing_suspended() then
            wait_until_processing_not_suspended()
            break -- continue
        end

        local item = queue:peekFront()

        if not item then
            wait_queue_non_empty()
            break -- continue
        end

        if item:onlyOnTuesdays() then
            wait_until_Tuesday()
            break -- continue
        end

        -- Now it's okay to go process the item

        queue:popFront()

        -- Process


I don't want to be annoying, but you could also write it as:

while true do

	if processing_suspended() then
		wait_until_processing_not_suspended()
	else

		local item = queue:peekFront()

		if not item then
			wait_queue_non_empty()

		elseif item:onlyOnTuesdays() then
			wait_until_Tuesday()

		else
			-- Now it's okay to go process the item

			queue:popFront()

			-- Process
		end
		
	end
	
end


--
Renato Maia
PhD student at PUC-Rio
__________________________
http://www.inf.puc-rio.br/~maia/