cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
ALopez
Level III

Looping over a List and concatenating a string

Hi,  I have a "List" and I want to concatenate each item with the suffix "_2020" and Insert it into a new list.
I have tried this code but I am missing something.  I will appreciate your input.

Thanks!

Names Default To Here( 1 );

FullNames ={};

todaysList = {"August", "July", "June", "May"};

TotalMs = N Items (todaysList);

For (i = todaysList, i <= TotalMs, i++,
	
	newName = (todaysList[i] ||"_2020");
	Insert Into (FullNames, newName),
	
);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Looping over a List and concatenating a string

Your For() loop starting index was invalid.  Here is your code with a slight modification to make it work

Names Default To Here( 1 );

FullNames ={};

todaysList = {"August", "July", "June", "May"};

TotalMs = N Items (todaysList);

For (i = 1, i <= TotalMs, i++,
	
	newName = todaysList[i] ||"_2020";
	Insert Into (FullNames, newName),
	
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Looping over a List and concatenating a string

Your For() loop starting index was invalid.  Here is your code with a slight modification to make it work

Names Default To Here( 1 );

FullNames ={};

todaysList = {"August", "July", "June", "May"};

TotalMs = N Items (todaysList);

For (i = 1, i <= TotalMs, i++,
	
	newName = todaysList[i] ||"_2020";
	Insert Into (FullNames, newName),
	
);
Jim
ALopez
Level III

Re: Looping over a List and concatenating a string

Yes, I can see my Index error, darn so obvious (after you mentioned).  What I still do not understand is the lack of parenthesis around the concatenation expression.  I will do some more reading.
Thank you very much.

Best regards,

Alfredo

Re: Looping over a List and concatenating a string

Hi,

 

Searching the Concat function in the JMP Scripting Index (Help->Scripting Index), it can be seen that use of the double bar operator doesn't require parentheses.  In case you weren't aware of it, the Scripting Index is a very powerful resource.

 

Capture.PNG