Basically a DWT Template allows you to iterate over arrays, but in the Package there is only one sort of array we can push ourselves, which is the Component Presentation array (which can contain Component Template TCMURIs, but also only Component TCMURIs).
Through this you can push (what I refer to as) a Dummy Component Array in the package which you can use to loop over and then through the double lookup feature, to make it work like looping over a set of Package variables.
For example, you push in the package a Component Array with three dummy TCMURIs (they can all be tcm:0-0-0, it doesn't matter what value they have). Then you create three package variables named: Var_0, Var_1, Var_2. Now in your DWT Template you can use:
<!-- TemplateBeginRepeat name="MyDummyArray" -->
@@Var_${TemplateRepeatIndex}@@
<!-- TemplateEndRepeat -->
Which will result you in the values of your three package variables.
Unfortunately there is no way to create a string array directly or a field array for that matter, so for everything you will want to loop over, you will have to use an existing field array, or create a "Dummy Component Array".
In your .Net assembly TBB you create the Component Array as follows:
ComponentPresentationList cpList = new ComponentPresentationList();
// add dummy uris in the array (as many times as you need)
// using Tridion.ContentManager.Templating.ComponentPresentation
cpList.Add(new ComponentPresentation(TcmUri.UriNull));
cpList.Add(new ComponentPresentation(TcmUri.UriNull));
cpList.Add(new ComponentPresentation(TcmUri.UriNull));
// push the array in the package
Item myDummyCPs = package.CreateStringItem(ContentType.ComponentArray, cpList.ToXml());
package.PushItem("MyDummyArray", myDummyCPs);
// and then push the values in the package too
package.PushItem("Var_0", package.CreateHtmlItem("first value"));
package.PushItem("Var_1", package.CreateHtmlItem("second value"));
package.PushItem("Var_2", package.CreateHtmlItem("third value"));
Update:
To react on the comment that this method could become to large for a high number of variables, with a little refactoring that shouldn't be an issue. Also the Package can contain quite a lot of variables and their values are usually quite small (I haven't seen errors related to having too much items in the package yet). I'm thinking along the lines of:
ComponentPresentationList cpList = new ComponentPresentationList();
// using Tridion.ContentManager.Templating.ComponentPresentation
for (int i = 0; i < count; i++)
{
// add a dummy uri to the array
cpList.Add(new ComponentPresentation(TcmUri.UriNull));
// push the value in the package
package.PushItem(string.Format("Var_{0}", i),
package.CreateHtmlItem("get the value from some array using [i]"));
}
// push the array in the package
Item myDummyCPs = package.CreateStringItem(ContentType.ComponentArray, cpList.ToXml());
package.PushItem("MyDummyArray", myDummyCPs);