Non-local returns

A block©s last expression may be preceded by an up-arrow (^).

This means that when the block completes execution it does not return to the caller (the activation that sent it value), but returns to the caller of the home activation (i.e., the activation corresponding to lexically-enclosing method).

	foo
		3 < 4 ifTrue: [^nil].
		...

	obj foo

Non-local returns

A block may end with a return statement, causing a return via the lexically- enclosing method activation. The return statement is an expression preceded by an up-arrow (^).


Exercise: Describe the steps taken in executing the following method, once the result of 3<4 is returned:

	3 < 4 ifTrue: [^nil]


Exercise: What are the effects of the following expressions?

	| b. z.
	 e = (| z <- 7.ÊÊdo: blk = ( blk value: z ) |)
	|
	b: 	[| :x.ÊÊy <- 1 |
		y: x + y.
		z: y + z.
		z printLine].
	b value: 3.
	b value: 4.
	e do: b.

[ Previous ] [ Index ] [ Next ]