Câu hỏi phỏng vấn Ruby
Câu hỏi

Is there an equivalent of “continue” in Ruby?

Câu trả lời

Yes, there is an equivalent of the "continue" keyword in Ruby, and it is called next. In Ruby, when you use the next keyword inside a loop, it skips the rest of the current iteration and immediately proceeds to the next iteration of the loop. This behavior is similar to the "continue" keyword found in languages like C and Java[2][3][8].

For example, if you want to skip odd numbers in a loop that iterates through an array of numbers, you could use next as follows:

ruby Copy
numbers = [1, 2, 3, 4, 5]
numbers.each do |number|
  next if number.odd?
  puts number
end

In this code, next is used to skip the rest of the...

entry

entry

Gợi ý câu hỏi phỏng vấn

entry

What can you say about an identifier that begins with a capital letter?

junior

What is the difference between an Instance Variable and a Class Variable?

senior

What will be the result of each of the following lines of code

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào