|
Pages: [1]
|
 |
|
Author
|
Topic: Fibonacci series (Read 681 times)
|
|
leke
|
I have been learning the WHILE loop in REBOL. The only examples in the Core Guide seem to use it in series like this:
colors: [red green blue yellow orange]
while [not tail? colors] [ print first colors colors: next colors ]
red green blue yellow orange
Could any one give me a REBOL version of this peice of code: >>> a, b = 0, 1 >>> while b < 10: ... print b ... a, b = b, a+b
I tried:
REBOL [] a: 0 b: 1 while [b < 100] [print b a: b b: a + b]
halt
but this is wrong somehow. It's meant to print out the Fibonacci series
|
|
|
|
|
Logged
|
|
|
|
|
DideC
|
The problem is on 'a In the pseudo code you try to implement, you affect 2 values to two vars in one line : ... a, b = b, a+b But the Rebol code you post doesn't do that : a: b b: a + b]
As the 'b value is affected to 'a, you have a = b and the last line mean b: b + bYou can solve the problem by picking the 'a value and affecting the 'b value to it just after, all this in the 'b computation : Rebol [] a: 0 b: 1 while [b < 100] [ print b b: a + a: b ]
|
|
|
|
|
Logged
|
|
|
|
RebolBert
Guest
|
Could any one give me a REBOL version of this peice of code: >>> a, b = 0, 1 >>> while b < 10: ... print b ... a, b = b, a+b
Yes : set [a b] [0 1] while [b < 10] [ print b set [a b] reduce [b a + b] ]
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2285 Posts in 594 Topics by 3708 Members
Latest Member: cialissactiv
|