Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > Transformation Development Kit (TDK) > Customizing an ACS Code Generator DLL > Working with SDL script > Iterating through linked items and items in lists in SDL script (TDK)
  
Iterating through linked items and items in lists in SDL script (TDK)
You can use a For loop to iterate through linked items or items in a list:
If you specify a link type for the current item, the For loop iterates through each item that is linked to the current item through that link type. For example, if the current item is a Class, you can iterate through its Attributes by specifying the Attribute link type.
If you use the %getlist or %getlocal list keyword and specify a list, the For loop iterates through each item in that list.
The current item is derived as follows:
ACS calls the top-level Generate.sdl generation template for each item (Model, Package or Class) that is selected either directly or indirectly for generation. On entering the Generate.sdl generation template, the selected Model, Package or Class is the current item.
The current item remains as the selected Model, Package or Class until a For loop iterates a collection of linked items or items in a list. During a For loop, the current item is the item that is currently being iterated.
After leaving a For loop, the current item reverts to the item that was the current item before entering the For loop.
For loop can be nested.
* 
There are SDL Script extensions for TDK. For more information, see Overview of SDL script extensions for TDK (SDL script).
The For loop uses the following keywords:
%for — starts the For For loop and specifies a link type for the current item or a list.
A link type is specified through the automation interface name of the link type that links the current item to other items. For more information about the automation interface names of link types, and then click the required item type. The link types are listed in the Associations section.
%separator — optional keyword to specify text for delimiting the output of each iteration. If you do not want a separator generated to the code with each iteration of the For loop, do not include this keyword.
%exit — optional keyword for exiting the For loop without processing all iterations. The %exit keyword is typically used with the evaluation of a condition.
%endfor — ends the For loop
Syntax
For a collection of items:
%for "<link type>" [%separator "<separator characters>"]
<set of statements>
[%exit]
%endfor
For a global list:
%for %getlist "<list name>" [%separator "<separator characters>"]
<set of statements>
[%exit]
%endfor
For a local list:
%for %getlocallist "<list name>" [%separator "<separator characters>"]
<set of statements>
[%exit]
%endfor
* 
The following examples are provided:
For loop processing linked items
For loop processing list
For loop using %exit keyword
For loop using the %separator keyword
For loop processing linked items
This example works in the context of an Operation and uses the Parameter automation interface association to process the Operation's Parameters. For each Parameter, it loads the Parameter.sdl template.
(
%for "Parameter"
%load "Parameter.sdl"
%endfor
)
For loop processing list
This example runs a set of statements against each item in the IncludedObjects list.
%for %getlist "IncludedObjects"
$ calculate and output the #include
%if %inlist "sysCurrentObject" %then
$ self so don't include
%else
%load "OutputInclude.sdl"
%setlocalvar "nGeneratedDependency" = 1
%endif
%endfor
For loop using %exit keyword
This example works in the context of a Class and uses the Attribute automation interface association to see if any of the Attributes owned by the Class have On Instance storage. If any Attributes have On Instance storage, the text '-- On instance attributes' is generated, and the For loop is exited because of the %exit keyword.
%for "Attribute"
%if %custom "Storage" == "on instance" %then
\t\t\t
"-- On instance attributes"
\n
%exit
%endif
%endfor
For loop using the %separator keyword
This example works in the context of an Operation and uses the Parameter automation interface association to process the Operation's Parameters. For each Parameter it loads the Parameter.sdl template. The text that is returned by the Parameter.sdl template for each Parameter is delimited by the specified comma and space.
(
%for "Parameter" %separator ", "
%load "Parameter.sdl"
%endfor
)