Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
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
Highlighted
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
Highlighted
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

Highlighted
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

Highlighted

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

 
Article Labels