Return Statement

Action

Returns control from a function to its calling function or from a child thread to its parent thread.

Syntax

return [expr]
Variable Description
expr Optional: An expression whose value is returned to the calling function. The type of the value returned must match the declaration for the function.

Notes

  • Use a return statement to return control from the function that currently has control to the function that called it. You can also use it to return a value to the calling function.

  • There is a return statement implied at the end of all 4Test functions, because when a 4Test function exits it automatically returns control to the function that called it.

Example

[-] testcase returnExample ()
	[ ] INTEGER i
	[ ] i = 5 
	[ ] Print (Square (i))
	[ ] i = -1
	[ ] NonNegative (i)
	[ ] 
[-] INTEGER Square (INTEGER i)
	[ ] return i * i
	[ ] 
[-] void NonNegative (INTEGER i)
	[-] if (i < 0) 
		[ ] return
	[-] else if (i == 0)
		[ ] Print ("i is zero")
	[-] else
		[ ] Print ("i =", i) 
	[ ] // This script prints: 25