Q1) Because you increment n when you hit 123, so the index is now 8 but your array only has 7 elements.
Q2) You could do it in a zillion way, the simplest one is like:

| myArray|

myArray := #(2 32 44 67 89 111 123).

1 to: 130 do: [:i | (myArray includes: i) ifTrue: [ Transcript show: i; cr ]].

-----------------
BenoƮt St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)


On Thursday, November 16, 2017, 3:19:49 AM EST, RedTigerFish <chihuyu@gmail.com> wrote:


Hello, *what I want is:*
From integers 1 to 130, I want to print some specific integers already given
in an array.
They are: 2 32 44 67 89 111 123 which are stored in small-to-big order.

*Here's my codes:*

|a n myArray|

myArray := #(2 32 44 67 89 111 123).

n := 1.
a := myArray at: n.

1 to: 130 do: [:i|
    i = a
    ifTrue: [
        Transcript show: i; cr.
        n := n + 1.
        a := myArray at: n.
        ].   
    ].

The output is very good except for an Error Message.

<http://forum.world.st/file/t371379/errormessage.png>

By my current level, I have no idea why that Error Message appears.

Q1: Why  Error Message appears ?
Q2: How can I improve that?






-----
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.
--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners