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?
The keyword next is the ruby equivalent of the continue keyword in other programming languages. The next keyword allows you to skip one iteration.
Ruby Next Keyword (Skip Iteration) The next keyword allows you to skip one iteration. Example: Let's say you're counting strings. And for some reason you don't want to count strings with a size of 4.
In a for loop, the continue keyword causes control to immediately jump to the update statement. In a while loop or do/while loop, control immediately jumps to the Boolean expression.
Yes, it's called next
.
for i in 0..5 if i < 2 next end puts "Value of local variable is #{i}" end
This outputs the following:
Value of local variable is 2 Value of local variable is 3 Value of local variable is 4 Value of local variable is 5 => 0..5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With