-
| first |
first := true.
range do: [:each |
first ifTrue: [frist := false] ifFalse: [Transcript show: ' '].
Transcript show: each]
However, in every dialect there is already a way to do this. For example, in Pharo we have a message #do:separatedBy::
range do: [:each | Transcript show: each] separatedBy: [Transcript show: ' ']
Another thing you can do is use Transcript spaceto get
range do: [:each | Transcript show: each] separatedBy: [Transcript space]
In addition, I would recommend a more general approach when you upload your string representation to a more general view of an object, for example WriteStream:
dump: range on: aStream
range do: [:each | each printOn: aStream] separatedBye: [aStream space]
now you can just write
<receiver> dump: range on: Transcript
to get the desired result.
source
share