Cython has moved to github.

cython-devel

view tests/run/for_decrement.pyx @ 1673:5730e9a933ef

Fix for #196
author Magnus Lie Hetland
date Fri Jan 30 15:53:16 2009 +0100 (3 years ago)
parents
children 9979b29367b6
line source
1 """
2 >>> range_loop_indices()
3 ** Calculating step **
4 (9, 9, 8, 1, 2)
5 >>> from_loop_indices()
6 ** Calculating step **
7 ** Calculating step **
8 ** Calculating step **
9 ** Calculating step **
10 ** Calculating step **
11 (10, 10, 0)
12 """
14 cdef int get_step():
15 """
16 This should only be called once, when used in range().
17 """
18 print "** Calculating step **"
19 return 2
21 def range_loop_indices():
22 """
23 Optimized integer for loops using range() should follow Python behavior,
24 and leave the index variable with the last value of the range.
25 """
26 cdef int i, j, k, l, m
27 for i in range(10): pass
28 for j in range(2,10): pass
29 for k in range(0,10,get_step()): pass
30 for l in range(10,0,-1): pass
31 for m in range(10,0,-2): pass
32 return i, j, k, l, m
34 def from_loop_indices():
35 """
36 for-from-loops should follow C behavior, and leave the index variable
37 incremented one step after the last iteration.
38 """
39 cdef int i, j, k
40 for i from 0 <= i < 10 by get_step(): pass
41 for j from 0 <= j < 10: pass
42 for k from 10 > k > 0: pass
43 return i, j, k