Looping @For not working properly

I have a text field called CONTENTS with value of “Text1, Text2, Text3, Text4, Text5, Text6”.

On another computed field called SHOWTEXT I have this formula:

temp:=“”;

textstring:=@Explode(contents);

@For(n:=1; n<@Elements(textstring); n:=n+1;temp:=textstring[n]);

temp

Problem: the SHOWTEXT field will only show “Text5”.

Seems like my loop is not working. I would appreciate any help, please? Thanks ahead!

Subject: Several things

Firstly, the loop condition needs to include the last element so you need to change n<@Elements(textstring) to n<=@Elements(textstring).

Secondly, each time in the loop you are replacing the value of temp rather than appending the value to it. So you need to change temp:=textstring[n] to temp:=temp+textstring[n].

Finally though I can’t see what you are trying to achieve with the loop.

Subject: Several things

That worked - thanks Wayne!

I’m actually using this to extract and process comma-delimited text inputs from users into other fields. This works perfectly fine. Thanks again for the tip.