简体   繁体   中英

Is there any way in which each do can go to the infinte loop in ruby

I am new to ruby, i am trying to create an endless loop in ruby,is there any way to create an endless using each do . I know by using for,while we can achieve it.

You can use the infinite loop :

loop do
  my_code
end

cycle is also an option if you want to loop on the same values over and over:

["a", "b", "c"].cycle { |x| puts x }  # print, a, b, c, a, b, c,.. forever.
(1..1.0/0).each do |i|
  your code
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM