lua-users home
lua-l archive

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


HI Jonathan,

Thanks for the reply!

Could you just give me an idea of the code, as if I try break it says its outside of the loop, and return doesnt exit the function loop, as I presume my if statements are causing issues,

An idea of my code is;

assert (dbh:query(todnew_query,function(todresult)
local t = os.date("*t");
if (tostring(todresult.year) == tostring(t.year) and tostring(todresult.month) == tostring(t.month)) then
       freeswitch.consoleLog("notice","Year and Month Match, next step is day of month\n")
       if (tostring(todresult.dayofmonth) == tostring(t.day)) then
         freeswitch.consoleLog("notice","This entry matches on Day of month too\n")
          return     <<---tried return or break here, is this correct?
        end
        if (tostring(t.day) >= startday) and (tostring(t.day) <= endday) then
          freeswitch.consoleLog("notice", "Today is in the time range\n")
       
      end
 end
end))

As for  SQL, its easy compared to Lua coding for me at the moment :) 

Thanks again.

Jon

On Mon, Sep 21, 2015 at 10:13 PM, Jonathan Goble <jcgoble3@gmail.com> wrote:
On Mon, Sep 21, 2015 at 5:03 PM, Jonathan Hunter
<jhunter@voxboxcoms.co.uk> wrote:
> I want it to exit the loop/function on true and not return any of the other
> entries,so in affect matches on first priority entry and stops there.

You can use the "break" keyword to exit the innermost loop
immediately, or the "return" keyword to immediately exit the current
function, including all loops within that function (and possibly send
value(s) back to the caller, by "return <value>").

Note that when using "break", you immediately lose any local variables
whose scope is the loop itself, including the loop variables
themselves, so be sure to store the entry in another variable before
"break"ing.

Beyond that, your database code is all Greek to me. :-) (One of these
days, I should learn some SQL. Might help me with a personal project
I'd like to do eventually.)




--
Jonathan Hunter
Technical Director /Telephony Developer
M:(+44) 7917 190 438
Email:jhunter@voxboxcoms.co.uk