Posted By

Shamaoke on 12/30/10


Tagged

exception stopiteration


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

JohnBing


StopIteration


 / Published in: Ruby
 

Terminate an infinitive loop by raising StopIteration exception

  1. # encoding: utf-8
  2.  
  3. arr = (1..10).to_a
  4.  
  5. loop do
  6. elm = arr.shift
  7. print elm, ' '
  8. raise StopIteration if elm == 4
  9. end
  10.  
  11. puts
  12.  
  13. #=> 1 2 3 4

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Jacky888 on October 16, 2018

the 8 best stand alone air purifier airpurifiers-review.com

You need to login to post a comment.