Project

General

Profile

Actions

Feature #3232

closed

Loops (while/until) should return last statement value if any, like if/unless

Added by Eregon (Benoit Daloze) almost 14 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:29920]

Description

=begin
In conditions:
if true
2
end #=> 2

In loops:
i = 0
while i < 3
i += 1
"return value"
end #=> nil

I suggest the return value of loops to be the return value of
the last "block" evaluated between "while/until" and "end".

It would be nil if the condition is not met from the first evaluation.

Is this reasonable to implement ?

It would come very handy in situations like:
while condition
...
my_method_return_value
end
my_method_return_value

because you could remove the last line.

The idea came up on ruby-talk: http://www.ruby-forum.com/topic/208978

Any thoughts?

Regards,
B.D.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0