<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Another thought: Give each of the blocks a "dirty bit" to symbolize falling/not falling instead of removing them from the collection.</span></div><div><span><br></span></div><div><span>Michael</span></div><div><br></div>  <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <font size="2" face="Arial"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Lars Wassermann &lt;lars.wassermann@student.hpi.uni-potsdam.de&gt;<br> <b><span style="font-weight: bold;">To:</span></b> beginners@lists.squeakfoundation.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Saturday, December 10, 2011 1:55 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [Newbies]
 Deleting elements from a Collection while looping through it<br> </font> <br>
Hey Jan,<br><br>changing a list you are iterating over is not a good idea.<br>Maybe return the changed list and save the changed list where the <br>parameter comes from:<br><br>doFallForAllIn: aSet<br>&nbsp; &nbsp;  ^ aSet select: [ :block | block fall ]<br><br>Another possibility would be iterating and afterwards deleting the <br>entries. But this is slower<br><br>doFallForAllIn: aSet<br>&nbsp; &nbsp;  aSet removeAll: (aSet reject: [ :block | block fall ])<br><br>Good luck,<br>Lars<br><br>Am 10.12.2011 20:43, schrieb Jan Teske:<br>&gt; Hey,<br>&gt;<br>&gt; I have a question concerning the behavior of Collections in Squeak.<br>&gt; Recently I face a problem when trying to delete some elements from a set<br>&gt; during a 'do:' message.<br>&gt; Have a look at this sample method:<br>&gt;<br>&gt;&nbsp; &nbsp; &nbsp;  doFallForAllIn: aSet<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  aSet do:<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  [:block |
 block fall ifFalse: [aSet remove: block]]<br>&gt;<br>&gt; It loops over a set of blocks and performs the fall message on each of<br>&gt; them. If a block is not falling I don't want it to be in aSet after the<br>&gt; function returned so I remove it from the set. Squeak doesn't seem to<br>&gt; like that since some rather strange error now occures: If a block is<br>&gt; removed from the set, the next block in the set will be left out from<br>&gt; looping... sometimes. Nearly all the time it works as exspected, only<br>&gt; sometimes a block is ignored. I couldn't find any pattern when this happens.<br>&gt;<br>&gt; So my question is: Has anyone an explanation for this? Does the error<br>&gt; occure because the way I'm doing it is fundamentally wrong? Or am I just<br>&gt; overlooking something and it is possible to remove blocks from a<br>&gt; collection while looping over it?<br>&gt;<br>&gt; Thanks in advance!<br>&gt;
 _______________________________________________<br>&gt; Beginners mailing list<br>&gt; <a ymailto="mailto:Beginners@lists.squeakfoundation.org" href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>&gt; http://lists.squeakfoundation.org/mailman/listinfo/beginners<br><br>_______________________________________________<br>Beginners mailing list<br><a ymailto="mailto:Beginners@lists.squeakfoundation.org" href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br><a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br><br><br> </div> </div>  </div></body></html>