ForEach set Do command

 ForEach set As name Do command

 ForEach set [As name] [Do]
   commands
 Next

Iteration over object array. The set is an array of objects, such as Ship or Planet. The loop will iterate through all objects in that set, and execute the command or command list for each of them.

By default, with no As name clause, the commands will be executed in an appropriate context, as if With were used. For example,

 ForEach Minefield Do
   If LastScan < Turn-10 Then Delete
 Next

will delete all minefields not seen within the last 10 turns.

If As name is given, name is a name of a variable. For each iteration, name will be set refer to the respective object. For example,

 Dim mf
 ForEach Minefield As mf Do
   If Distance(mf, 1010, 1020) < mf->Radius Then Print mf->Id
 Next

will print the Ids of all minefields that cover (1010,1020). This syntax is available since PCC2 2.40.7.

See also: Break, Continue, For, Do, Count(), Find(), Elementary Commands

This is a testing version.
It may be incomplete, and have more bugs (or features) than the public live version at planetscentral.com.