Tobias Haagen Michaelsen
2007-May-14 22:03 UTC
SV: [Rails-spinoffs] Returning (not only breaking) from a Hash.each()
Try something like:
function f() {
...
if (myHash.find(function(item) { return !o.isOk; })) {
return;
}
... //not always executed
}
-Tobias
-----Oprindelig meddelelse-----
Fra: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org på vegne af
Christophe Moine
Sendt: ma 14-05-2007 23:45
Til: Ruby on Rails: Spinoffs
Emne: [Rails-spinoffs] Returning (not only breaking) from a Hash.each()
Hi,
How can I achieve the equivalent of the following code with a
Hash.each() iterator ? :
function f() {
...
for (var i in o) {
if (!o.isOk) {
return;
}
}
... //not always executed
}
My problem is how to implement the RETURN statement.
For if I write this :
function f() {
...
myHash.each (
function(item) {
if (!o.isOk) {
return;
}
}
);
... //always executed !!!
}
here the return statement is equivalent of a simple break of the loop,
whereas I really want to quit the top function !
Any idea ?
Christophe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Christophe Moine
2007-May-16 06:43 UTC
Re: Returning (not only breaking) from a Hash.each()
That works, thanks ! Christophe --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---