What is difference between break statement and return statement?

What is difference between break statement and return statement?

···

--
Posted via http://www.ruby-forum.com/.

hi,

Break statement terminate the loop as below

(1..10).each do |i|
  puts i
  break if i.eql?5
end

This loop will be terminated when I reach 5.

but return will return from the function the caller function like

def hi
    a=hello
    puts a
end

def hello
    return 12
end

hi

···

--
Posted via http://www.ruby-forum.com/.

To summarise this answer

Break exits from the innermost loop

Return exits from the function

···

On Wed, Feb 19, 2014 at 10:23 PM, Jaimin Pandya <lists@ruby-forum.com>wrote:

What is difference between break statement and return statement?

--
Posted via http://www.ruby-forum.com/\.

--
Daniel Nitsikopoulos
t: @nitza
f: dNitza

@Rajagopalan: Your answer is useful for me. Thank you.

@Dan: I understand clearly from link. Thank you.

···

--
Posted via http://www.ruby-forum.com/.