I am using Smalltalk to type in Transcript window a 1-9 multiplication table .
Here is my code:
1 to: 9 do: [:i|
1 to: i do: [:j|
Transcript show: j.
Transcript show: ' * '.
Transcript show: i.
Transcript show: ' = '.
Transcript show: j * i.
Transcript show: ' '.
].
Transcript show: ' '; cr.
].
As can be seen, the above code, although working fine, looks far from beautiful and concise.
I had hoped to write something like :
Transcript show: j '*' i '=' j * i.
Unfortunately, they are wrong. I remember C has a very nice way to handle that issue of mine.
Like, printf("%d * %d = %d ", j, i, j * i);
Is there a more elegant way to make Smalltalk codes elegant in this situation ?
Peter solves this problem. Thanks.
More to ask:
How to display "Escape character" in Smalltalk.
I know in C, printf("%d * %d = %d\n", j, i, j * i);
seems fine.
But in Smalltalk, Transcript show: ('{1} * {2} = {3}cr.' format: {i. j. i * j}).
is not OKAY.
How can I solve that?