[Pharo-project] smalltalk: breaking out of a loop..
if i have an OrderedCollection called people.. if i have a million ordered pairs in there, and i wanna see af any one of them (hasTenBucks = true). i don't want to iterate all of them, i want to stop when i find that one hasTenBucks.. so in something like: people do: [ :person | (person hasTenBucks) ifTrue; [break out of loop] ] ideas? thanks! -- ---- peace, sergio photographer, journalist, visionary http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
use #dectect: On 07.11.2010, at 17:04, sergio_101 wrote:
if i have an OrderedCollection called people..
if i have a million ordered pairs in there, and i wanna see af any one of them (hasTenBucks = true).
i don't want to iterate all of them, i want to stop when i find that one hasTenBucks..
so in something like:
people do: [ :person | (person hasTenBucks) ifTrue; [break out of loop] ]
ideas? thanks!
-- ---- peace, sergio photographer, journalist, visionary
http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
On Sun, Nov 7, 2010 at 11:08 AM, Max Leske <maxleske@gmail.com> wrote:
use #dectect:
perfect.. thanks! -- ---- peace, sergio photographer, journalist, visionary http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
#anySatisfy: does not iterate over the entire collection either. So if you only want to know if there is one that satisfies the condition... this is the message you're looking for. Cheers! Guille On Sun, Nov 7, 2010 at 1:27 PM, sergio_101 <sergio.rrd@gmail.com> wrote:
On Sun, Nov 7, 2010 at 11:08 AM, Max Leske <maxleske@gmail.com> wrote:
use #dectect:
perfect..
thanks! -- ---- peace, sergio photographer, journalist, visionary
http://www.CodingForHire.com http://www.coffee-black.com http://www.painlessfrugality.com http://www.twitter.com/sergio_101 http://www.facebook.com/sergio101
On 11/07/2010 08:06 PM, Guillermo Polito wrote:
#anySatisfy: does not iterate over the entire collection either. So if you only want to know if there is one that satisfies the condition... this is the message you're looking for.
Cheers! Guille
And finally, a generic "trick" for breaking out of loops (not just iterations over collections): Factor out the loop in a single method, then call it. When you want to break out, just do a normal return! regards, Göran
participants (4)
-
Guillermo Polito -
Göran Krampe -
Max Leske -
sergio_101