Hello,
I am trying to learn about squeak and writing a method to compute factorial using a loop. Here's my code
=========== fact "an alternative to factorial method"
| answer end |
answer := 1. end := self.
1 to: end do: [:index | answer := answer * index.
Transcript show: (answer printString), ' ', (index printString); cr. ] ============
The output looks fine, but when I call this method all that gets returned is the original value sent. Please help me clear this hurdle.
mv
Hi Mark, You might want to send your query to the "Squeak.org" mailing list which is "populated" /read by more programmers /"cs types" than teachers, parents and kids....the Squeakland list is comprised mostly of people using the "etoy"/tile interface of Squeak than with this kind of code. cheers and good luck! Kim
Hello,
I am trying to learn about squeak and writing a method to compute factorial using a loop. Here's my code
=========== fact "an alternative to factorial method"
| answer end |
answer := 1. end := self.
1 to: end do: [:index | answer := answer * index.
Transcript show: (answer printString), ' ', (index printString); cr. ]
The output looks fine, but when I call this method all that gets returned is the original value sent. Please help me clear this hurdle.
mv
--
Hi Mark --
You need to return the value of answer.
You can do this by adding
^ answer.
at the end of the method.
(Don't forget to put a period between the "]" and before this line.)
Having said this, let me refer you to http://www.squeak.org. This site is for people who program in Squeak proper.
This http://squeakland.org site is for teachers, parents, and others who are working with the etoys part of Squeak for children.
Cheers,
Alan
------
At 11:44 AM -0600 2/12/03, Vellinga, Mark wrote:
Hello,
I am trying to learn about squeak and writing a method to compute factorial using a loop. Here's my code
=========== fact "an alternative to factorial method"
| answer end |
answer := 1. end := self.
1 to: end do: [:index | answer := answer * index.
Transcript show: (answer printString), ' ', (index printString); cr. ]
The output looks fine, but when I call this method all that gets returned is the original value sent. Please help me clear this hurdle.
mv
--
squeakland@lists.squeakfoundation.org