patternrubyCritical
Equivalent of "continue" in Ruby
Viewed 0 times
equivalentcontinueruby
Problem
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?Solution
Yes, it's called
This outputs the following:
next.for i in 0..5
if i < 2
next
end
puts "Value of local variable is #{i}"
endThis 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..5Code Snippets
for i in 0..5
if i < 2
next
end
puts "Value of local variable is #{i}"
endValue of local variable is 2
Value of local variable is 3
Value of local variable is 4
Value of local variable is 5
=> 0..5Context
Stack Overflow Q#4010039, score: 1090
Revisions (0)
No revisions yet.