Takes a variable number of parameters, QueryName, MethodName, [Param1, [Param2, etc...]]


For each Record in QueryName, call the Private Method named MethodName, using the following Parameters.

When the system calls the Private Method, it will start with MethodName.Input as the Top Query with any Parameters populated from the ForEach call. The Work Query, named MethodName.Output, will be populated with a copy of the single Record used for this iteration. Both of these Queries will automatically be reset/repopulated on each iteration.

Since the MethodName.Output Query is reset every time, the intended output of a ForEach is often directly to one of the various Html related commands, or the output of each iteration will be copied via an AppendQuery or a JoinQuery command to another Query. Fully coupled Methods and ForEach Methods may reference a Query name from the caller directly. Uncoupled ForEach Methods should indicate the destination Query via a parameter.

ForEach should only be used for relatively small data sets, typically a few dozen at most. Larger data sets, ForEach will be much slower than designing a solution that only uses other Work Query commands and logic.


LoadTable "MemTab.Person"
ForEach "Output", "ShowPersonGroups", "[hr]"
Method ShowPersonGroups(pSeparator)
  [New] FullName
  FullName | MemTab.Person.FirstName & " " & MemTab.Person.LastName
  Html ((pSeparator & "[h2]" & FullName & "[/h2]"))
  Children "MemTab.Group"
  KeepFields "MemTab.Group.Alias MemTab.Group.Name MemTab.Group.Type"
End Method