Taking action on more than one subitem

Gosu provides a for(... in ...) syntax and an if(...) { then do something } syntax that you can use to construct fairly complicated actions. In the following example, the rule iterates through the various lines on a policy to determine if a line contains a certain Coverage Group.

for (line in policyPeriod.Lines) {
  for (cov in line.AllCoverages) {
    if (cov.CoverageCategory == "BAPHiredGrp") {
      print( "PolicyLine \"" + line + "\" has BAPHiredGroup coverage" )
    }
  }
}

Notice that the curly braces ({}) mark the beginning and end of a block of Gosu statements:

  • The outer pair of braces contain statements to perform “for” each line on the policy.
  • The outer pair of braces contain statements to perform “if” the specified coverage group is found.
You can use the Length method on a subobject to determine how many subobjects exist. For example, if there are five lines on this PolicyPeriod, then the following expression returns the value 5:
  • PolicyPeriod.Lines.Length

See also