mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
fixes #4220
This commit is contained in:
@@ -2005,7 +2005,13 @@ iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
|
||||
## step count. `T` may be any ordinal type, `step` may only
|
||||
## be positive. **Note**: This fails to count to ``low(int)`` if T = int for
|
||||
## efficiency reasons.
|
||||
when T is IntLikeForCount:
|
||||
when T is (uint|uint64):
|
||||
var res = a
|
||||
while res >= b:
|
||||
yield res
|
||||
if res == b: break
|
||||
dec(res, step)
|
||||
elif T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res >= int(b):
|
||||
yield T(res)
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
discard """
|
||||
output: '''true
|
||||
true
|
||||
true'''
|
||||
true
|
||||
5
|
||||
4
|
||||
3
|
||||
2
|
||||
1
|
||||
0
|
||||
it should stop now
|
||||
'''
|
||||
"""
|
||||
|
||||
# bug 1420
|
||||
@@ -11,3 +19,15 @@ echo x > y # works
|
||||
|
||||
echo((40'i32) > (30'i32))
|
||||
echo((40'u32) > (30'u32)) # Error: ordinal type expected
|
||||
|
||||
# bug #4220
|
||||
|
||||
const count: uint = 5
|
||||
var stop_me = false
|
||||
|
||||
for i in countdown(count, 0):
|
||||
echo i
|
||||
if stop_me: break
|
||||
if i == 0:
|
||||
echo "it should stop now"
|
||||
stop_me = true
|
||||
|
||||
Reference in New Issue
Block a user