File: fib.ft

package info (click to toggle)
fudgit 2.42-6
  • links: PTS
  • area: non-free
  • in suites: potato, woody
  • size: 2,468 kB
  • ctags: 2,375
  • sloc: ansic: 27,729; makefile: 793; yacc: 724; lex: 102; asm: 29; fortran: 15
file content (33 lines) | stat: -rw-r--r-- 529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Play safe
free @all
# Print Fibonacci numbers
cmode
	proc fib(x) {  # This x is a prototype
		# a, b, c will all be defined as global variables
    	a = 0 
    	b = 1 
    	while (b < x) { 
			print b, "\n"
        	c = b 
        	b += a 
        	a = c 
    	} 
	} 
	
	proc fib2(x) {
		auto a,b,c  # These a,b,c are local and hide global a,b,c above

		for(a=0,b=1;b<x;c=b,b+=a,a=c) {
			b    # This is equivalent to (print b, "\n")
		}
	}
	
	i=1
	while (i++<10) {
		fib(1000)
	}
	i=1
	while (i++<10) {
		fib2(1000)
	}
fmode