Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a non-local return?

What is non local return? In what scenarios it is useful? Please give an example to explain.

like image 225
dalibocai Avatar asked Jan 17 '12 15:01

dalibocai


2 Answers

Here's a good article on the use of non local returns in the context of ruby blocks.

Ruby’s blocks support non-local-return (some references), which means that a return from the block behaves identically to returning from the block’s original context.

It basically mean that you can call a block from a function, and the block has the ability to return from the original function.

like image 188
recursive Avatar answered Oct 14 '22 12:10

recursive


It means exiting a function and ending up someplace else beside where the function was called. It's primarily used to refer to exceptions (i.e., try, throw, and catch in Java and C++), but it can also mean mechanisms like setjmp/longjmp in C.

like image 23
Ernest Friedman-Hill Avatar answered Oct 14 '22 12:10

Ernest Friedman-Hill