The foreach statement iterates through all the members of a list or a table. The syntax of the foreach statement is:

foreach variable (listortablename) {statements}

When the foreach statement is used with a loop, the variable stores the value of each member of the list every time the foreach statement loops. The members returned are in numerical order by their list indices.

Building on our ServiceSubscriber example above, add the following statements:

EXPORT_SERVICESUBSCRIBER {
} do {
 svcSubList = getInstances("ServiceSubscriber")? LOG, NEXT;
 foreach svcSub (svcSubList) {
  builder->addObject(svcSub, "ServiceSubscriber");
  builder->addAttribute(svcSub, "DisplayName");
  builder->addObjectClosing();
    }
}