<div id="__MailbirdStyleContent" style="font-size: 12pt;font-family: calibri;color: #000000">
                                        
                                        
                                            
                                        
                                        
                                        Hi, there.<div class="mb_sig"></div>
                                        
                                        <div><br></div><div>If you want to abort some kind of repetition/enumeration in Smalltalk and "method return" is an option, sure, then you can just do that as stated in the examples before.</div><div><br></div><div>Else, consider the following examples, which might not be considered "idiomatic" but should illustrate aspects of the solution space --- especially in prototypical/exploratory source code:</div><div><br></div><div>#(a b c d 1 2 3) detect: [:each |</div><div>   each isNumber</div><div>      ifFalse: [T<span style="font-size: 12pt;line-height: 1.5">ranscript showln: each. false "continue"]</span></div><div><span style="font-size: 12pt;line-height: 1.5">      ifTrue: [true "break"]].<br></span></div><div><span style="font-size: 12pt;line-height: 1.5"><br></span></div><div>break := false.</div><div>things := #(a b c d 1 2 3).</div><div>i := 0.</div><div>[break or: [i = things size]] whileFalse: [ | each |</div><div>   i := i + 1.</div><div>   e<span style="font-size: 12pt;line-height: 1.5">ach := things at: i.</span></div><div>   each isNumber</div><div>      ifFalse: [Transcript showln: each]</div><div>      ifTrue: [break := true]].</div><div><br></div><div>break := false.</div><div>(1 to: 1000) detect: [:ea |</div><div>   "Do some work here. Switch 'break' if needed."</div><div>   break] ifNone: ["All numbers enumerated."].</div><div><br></div><div>In general, you should not have to "break" such kind of object enumeration in Smalltalk. Just select the objects you want to send a message to:</div><div><br></div><div>myThousandsOfObjects</div><div>   select: [:each | each shouldParticipate]</div><div>   thenDo: [:each | each doSomeWork].</div><div><br></div><div>Best,</div><div>Marcel</div><div><br></div><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 17.11.2017 07:54:34 schrieb Bernhard Pieber <bernhard@pieber.com>:</p>Well, the first statement is the keyword message #to:do: sent to the receiver 1 with the parameters 130 and a one-argument block. The second is the keyword message #timesRepeat: sent to the receiver 100 with a zero-argument block as a parameter. What I meant is that it is no different from any other message send like 3 + 4. Neither looping nor conditionals are part of the syntax. None of the usual suspects like if, else, for, while etc. are reserved words. What follows is you can easily implement all kinds of useful „loop“ types yourself just by using messages and block closures.<br><br>main<br>      1 to: 5 do: [:i | i = 50 ifTrue: [^self]]<br><br>However, this is not an ideal example to show idiomatic Smalltalk. Here is one from the Collection class:<br><br>allSatisfy: aBlock<br>  "Evaluate aBlock with the elements of the receiver.<br>      If aBlock returns false for any element return false.<br> Otherwise return true."<br><br>        self do: [:each | (aBlock value: each) ifFalse: [^ false]].<br>   ^ true<br><br>The message enumerates the collection and as soon as an element is found, which does not satisfy the condition given by the block, it returns false from the method and therefore also breaks out of the loop.<br><br>Cheers,<br>Bernhard<br> <br>> Am 17.11.2017 um 07:00 schrieb RedTigerFish <chihuyu@gmail.com>:<br>> <br>> *1 to: 130 do: [:i| ] *  or  *100 timesRepeat: [ ] *<br>> <br>> Maybe because I learned some C before. I thought the above two are loops.<br>> <br>> <br>> The following is "break" example in C. How to implement that in Smalltalk? <br>> <br>> #include <stdio.h><br>> void main() <br>> {   <br>>     for (int i = 0; i < 100;="" i++)=""><br>>         if (i == 50) <br>>              break; <br>> }<br>> <br>> <br>> <br>> -----<br>> Dig, dig where you are,<br>> Down below's well.<br>> Let those that walk in darkness shout, <br>> Down below's hell.<br>> --<br>> Sent from: http://forum.world.st/Squeak-Beginners-f107673.html<br>> _______________________________________________<br>> Beginners mailing list<br>> Beginners@lists.squeakfoundation.org<br>> http://lists.squeakfoundation.org/mailman/listinfo/beginners<br><br>_______________________________________________<br>Beginners mailing list<br>Beginners@lists.squeakfoundation.org<br>http://lists.squeakfoundation.org/mailman/listinfo/beginners<br></stdio.h></chihuyu@gmail.com>
                        </blockquote></div>