source:
doc/papers/concurrency/examples/Fib.py@
758c9ef
Last change on this file since 758c9ef was a573c22, checked in by , 6 years ago | |
---|---|
|
|
File size: 326 bytes |
Line | |
---|---|
1 | def Fib(): |
2 | fn = 0; fn1 = fn; yield fn # suspend |
3 | fn = 1; fn2 = fn1; fn1 = fn; yield fn |
4 | while True: |
5 | fn = fn1 + fn2; fn2 = fn1; fn1 = fn; yield fn |
6 | |
7 | f1 = Fib() |
8 | f2 = Fib() |
9 | for i in range( 10 ): |
10 | print( next( f1 ), next( f2 ) ) # resume |
11 | |
12 | # Local Variables: # |
13 | # tab-width: 4 # |
14 | # compile-command: "python3.7 Fib.py" # |
15 | # End: # |
Note:
See TracBrowser
for help on using the repository browser.