Skip to content

7.2 wrong start #17

@b10s

Description

@b10s

https://github.com/xfbs/PiL3/blob/master/07Iterators/fromtostep.lua
Hey, again : )

your code gives:

> for i in fromto(3,7,2) do print(i) end
4
6

but should be:

> for i in fromto(3,7,2) do print(i) end
3
5
7

my code:

function fromto(f,t,s)                                                              
    local iter; iter = function(s)                                                  
        s[1] = s[1] + s[3]                                                          
        if s[1]<=s[2] then                                                          
            return s[1]                                                             
        else                                                                        
            return nil                                                              
        end                                                                         
    end                                                                             
    return iter, {f-s,t,s}                                                          
end  

https://github.com/xfbs/PiL3/blob/master/07Iterators/fromtostep.lua#L26
min-1 should be min-step i guess

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions