我得使用Smalltalk返回n th斐波那契數,我以前沒有用過這種語言。這個程序返回1到任何輸入,我不知道爲什麼。它甚至沒有迭代我認爲的for循環。有人能幫助我嗎?謝謝。Smalltalk斐波那契
'Which fibonacci number do you want? (n>2)' printNl.
n := stdin nextLine asInteger.
(n <= 2)
ifTrue: ['Type a larger number, F(1) and F(2) equals 1!' displayNl.]
ifFalse: [
result:= 1.
parent := 1.
gparent := 1.
2 to: n do: [ :i | [
result := (parent + gparent).
gparent := parent.
parent := result.
'come on, do something' displayNl.
]
].
result displayNl.
].
非常感謝。 – appl3r