发布日期: 09/18/2023

Recursion

The Recurse() function makes a recursive call of the defining function. For example, you can make a function to calculate factorials. A factorial is the product of a number, the number minus 1, the number minus 2, and so on, down to 1.

myfactorial = Function( {a},
	If( a == 1,
		1,
		a * Recurse( a - 1 )
	)
);
myfactorial( 5 );

120

You can define recursive calculations without using Recurse(). For example, you could replace Recurse() by myfactorial, and the script would still work. However, Recurse() offers these advantages:

It avoids name conflicts when a local variable has the same name as the function.

You can recurse even if the function itself has not been named (for example, assigned to a global variable, such as myfactorial above).

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