What is difference between break statement and return statement?
on 2014-02-19 12:23
on 2014-02-19 12:27
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 to the caller function like def hi a=hello puts a #will be printed 12 end def hello return 12 end hi
on 2014-02-19 12:32
To summarise this answer http://stackoverflow.com/a/4601654 Break exits from the innermost loop Return exits from the function
on 2014-02-19 16:07
@Rajagopalan: Your answer is useful for me. Thank you. @Dan: I understand clearly from link. Thank you.