Main Content

Ruby, C, Java and more - getting out of loops

Archive - Originally posted on "The Horse's Mouth" - 2008-03-19 16:07:01 - Graham Ellis

break and continue statements have been available for loop control for many years, and others functionallity has been added such as Perl's redo. From today's Ruby Course, here's a table that compares these loop controls in Ruby to similar commands in the other languages that I have been discussing with this week's course.

C/JavaPerlRubyeffect
breaklastlastGet me out the loop NOW!
continuenextnextgo for the next loop iteration
-redoredorerun current loop iteration
--retrylet's start the loop again, should we?