For the latest version of JMP Help, visit JMP.com/help.


Publication date: 04/28/2021

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).

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).