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.
By my current level, I have no idea why that Error Message appears.
Q1: Why Error Message appears ?
Q2: How can I improve that?
Update:
I found another way to solve this issue:
|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.
n = 8
ifTrue: [n := n - 1].
a := myArray at: n.
].
].
Looks ugly though.
Updated again:
|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.
(n = 8) ifTrue: [^'Found it!'].
a := myArray at: n.
].
].
From integers 1 to 130, I want to print some specific integers already given in an array
1 to: 130 do: [ :i |
(array includes: i) ifTrue: [ Transcript show: i; cr. ] ]