more G-Labs products

Author Topic: return True/False explanation  (Read 1227 times)

February 19, 2014, 03:48:22 PM
Read 1227 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Can you explain why sometimes the following code returns true and others false?  I'm not sure how the statement is used in this scenario.

Code: [Select]
var smart_devices = Modules.WithFeature(SMART_LIGHT_ENABLE);
smart_devices.Each((mod)=>
{
  if (module.Instance.Name=="Entry Light"))
  {
    //code to do stuff
    ...
  }
     
  return true;
});

February 19, 2014, 04:00:29 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
If you return true, the iteration will break. If you return false, it will continue iterating to the next element in the selection.
I made a correction the the api docs so it should be more clear:

http://www.homegenie.it/docs_old/api/modules.html#each

g.

February 19, 2014, 04:46:36 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That makes sense.  Thanks!