For-Each Loop

There are several different ways in which you can loop on a collection, however the recommended method is to use a For-Each loop, in which Sax Basic automatically sets an object variable to return every object in the collection. This structure is very powerful and allows you to loop through all the elements in an array, too.

One of the benefits of this structure is that you don't need to know in advance how many elements have been filled in the array. Its real power, however, is in the manipulation of collections of objects:

Sub ExampleForEach()
  Dim prj As PslProject
  Set prj = PSL.ActiveProject
  Dim lng As PslLanguage

  For Each lng In prj.Languages
    prj.LogMessage( lng.LangCode)
  Next lng
End Sub

In this example, all languages within the active SDL Passolo project are listed in the output windows.