views:

86

answers:

5

In C and many other languages, there is a continue keyword that, when used inside of a loop, jumps to the next iteration of the loop. Is there any equivalent of this continue keyword in Ruby?

Thanks in advance!

+1  A: 

Inside for-loops and iterator methods like each and map the next keyword in ruby will have the effect of jumping to the next iteration of the loop (same as continue in C).

However what it actually does is just to return from the current block. So you can use it with any method that takes a block - even if it has nothing to do with iteration.

sepp2k
as well as nice redo statement
c0r0ner
+1  A: 

I think it is called next.

idursun
+5  A: 

Yes, it's called next.

for i in 0..5
   if i < 2 then
      next
   end
   puts "Value of local variable is #{i}"
end
Ian Purton
+2  A: 

next

also, look at redo which redoes the current iteration.

invariant
+1  A: 

Just for information, exists redo and retry to iterations control. More information about this in Ruby Quicktips: http://rubyquicktips.tumblr.com/post/1122838559/redo-vs-retry

Wagner Andrade