Flow of Control in Loops - UNTIL

Computing Fibonacci Numbers

 

fibonacci_1 <- 0
fibonacci_2 <- 1
counter <- 2
read number
repeat until counter = number
    next <- fibonacci_1 + fibonacci_2
    (Remember last two values)
    fibonacci_1 <- fibonacci_2
    fibonacci_2 <- next
    counter = counter + 1
write "The ", number,"-th Fibonacci number is ", next
STOP

EXECUTE THE ALGORITHM

[Prev][TOC][Next]


Last updated 2000/01/25
© J.A.N. Lee, 2000.