In addition to conditionals, loops, and iterators, Ruby supports a number of statements that alter the flow-of-control in a Ruby program. These statements are:
Causes a method to exit and return a value to its caller.
Causes a loop (or iterator) to exit.
Causes a loop (or iterator) to skip the rest of the current iteration and move on to the next iteration.
Restarts a loop or iterator from the beginning.
Restarts an iterator, reevaluating the entire expression. The
retry keyword can also be used
in exception handling, as we’ll see later in the chapter.
A very general control structure that is named like
and works like an exception propagation and handling mechanism.
catch are not Ruby’s primary exception
mechanism (that would be
rescue, described later in
this chapter). Instead, they are used as a kind of multilevel or
The subsections that follow describe each of these statements in detail.
return statement causes
the enclosing method to return to its caller. If you know C, Java, or
a related language, you probably already have an intuitive
understanding of the
statement. Don’t skip this section, however, because the behavior of
return within a block may not be
intuitive to you.
return may optionally be
followed by an expression, or a comma-separated list of expressions.
If there is no expression, then the return value of the method is
nil. If there is one expression, then the value ...