发布日期: 09/18/2023

Iterate through a List

Iterate through a list to do something with each value or look for a particular value. The following JSL script looks at each item in the list. If the item in the list is less than or equal to 10, it is replaced with its square.

x = {2, 12, 8, 5, 18, 25};
n = N Items( x );
For( i = 1, i <= n, i++,
	If( x[i] <= 10,
		x[i] = x[i] ^ 2
	)
);
Show( x );

x = {4, 12, 64, 25, 18, 25};

You can use Loc() to locate the items in the new list that are equal to 25:

Loc( x, 25 );

[4, 6] // The fourth and sixth items in the list are equal to 25.

需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).