<div dir="ltr"><div>Okay, it looks like you did the work. So I'll offer an alternative.</div><div>Move the 'a' assignment to the top of the loop, immediately preceded by the bounds check,</div><div>with the beneficial side-effect that the loop exits earlier.</div><br>myArray := #(2 32 44 67 89 111 123).<br>i := 1.<br>n := 1.<div>nMax := myArray size.<br>[ (i <=130) and: (n<=nMax) ] whileTrue: </div><div>[    a := myArray at: n.</div><div><div>    (i = a) ifTrue: </div><div>    [   Transcript show: i; cr.<br>        n := n +1.<br>    ].</div><div>].</div><div><br></div><div><br></div><div>> <span style="font-size:12.8px">I think "array includes: i"  is nice. But I guess my way is faster. Correct</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">yes. </span><span style="font-size:12.8px">But is #includes: fast enough?  You are trading *one* line of code for *ten*.  </span></div><div><span style="font-size:12.8px">That makes  #includes:  faster write, so you stay more in-the-zone of your application domain,</span></div><div><span style="font-size:12.8px">and forever-after makes it faster to understand every time your read your code.</span></div><div><span style="font-size:12.8px"><br></span></div><div>You should avoid premature optimisation, and only use your implementation once benchmarks show its a problem.</div><div><br></div><div>cheers -ben</div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On 17 November 2017 at 10:57, RedTigerFish <span dir="ltr"><<a href="mailto:chihuyu@gmail.com" target="_blank">chihuyu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">*Update:*<br>
<br>
I found another way to solve this issue:<br>
<br>
|myArray|<br>
<br>
myArray := #(2 32 44 67 89 111 123).<br>
<br>
n := 1.<br>
a := myArray at: n.<br>
<br>
1 to: 130 do: [:i|<br>
    i = a<br>
    ifTrue: [<br>
        Transcript show: i; cr.<br>
        n := n +1.<br>
        a := myArray at: n.<br>
        n = 7<br>
        ifTrue: [n := n - 1].<br>
        ].<br>
    ].<br>
<br>
<br>
*Looks ugly though*<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: <a href="http://forum.world.st/Squeak-Beginners-f107673.html" rel="noreferrer" target="_blank">http://forum.world.st/Squeak-B<wbr>eginners-f107673.html</a><br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org" target="_blank">Beginners@lists.squeakfoundati<wbr>on.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://lists.squeakfoundation.<wbr>org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div></div></div></div></div>