Is there no continue keyword for Ruby?

Asked 2 years ago, Updated 2 years ago, 75 views

Is there no continue keyword for Ruby?

I created a code that just passes the number less than 2 out of the numbers from 0 to 5, but I'm embarrassed that there's no continue here.

for i in 0..5
   If i < 2 then #2 does not output less than 2
     continue
   end
   puts "Value: #{i}"
end
`block in <main>': undefined local variable or method `continue' for main:Object (NameError)
from `each'
from `<main>'

keyword ruby

2022-09-21 22:17

1 Answers

Ruby writes next instead of continue.

for i in 0..5
   if i < 2 then
     Next # I changed it
   end
   puts "Value: #{i}"
end


2022-09-21 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.