For Each command - counting iterations

Is there a way to interact with specific iterations of this looping structure. I would like to do something different for the first iteration (or any other specific line in future). Apologies for what I suspect is a basic ORDA question. Just getting to grips with this.

Thanks Steve

If you are looping an entitySelection or objects in collections, you can use indexOf() for getting the current iteration.

That’s right, but will it work if the collection contains multiple instances of the same object?

That said, I think one should just avoid inserting multiple instances of the same object, especially when planning to use indexOf().

Using indexOf() will be slow for large collections won’t it? More efficient to just keep track of the current index.

For each ($item;$collection)
	If ($i=123)
		  //do something special
		  //do something normal
	End if 
End for each 

I wouldn’t lose sleep over that…just set a boolean flag after the first round.

True, many different way to achieve the same outcome. :slightly_smiling_face:

Thank you everyone. Adams code suits well for this purpose.