OILS / opy / gold / fib_iterative.py View on Github | oilshell.org

30 lines, 17 significant
1#!/usr/bin/env python2
2from __future__ import print_function
3"""Iterative version of Fibonacci."""
4
5i = 0
6n = 10
7a = 0
8b = 1
9
10while 1: # Slightly easier to compile than 'while True:'
11
12 # Artificial change to test 'continue'
13 if i == 0:
14 i = i + 1
15 continue
16
17 print(b)
18
19 # NOTE: This would generate BUILD_TUPLE and UNPACK_SEQUENCE bytecodes.
20 #a, b = b, a+b
21
22 tmp = a
23 a = b
24 b = tmp + b
25
26 i = i + 1 # Don't use augmented assignment
27 if i == n:
28 break
29
30print('Done fib_iterative.py') # To make sure we implemented 'break' properly