Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break in for-range loop will leave garbage #1

Closed
AlekSi opened this issue Jun 23, 2015 · 2 comments
Closed

break in for-range loop will leave garbage #1

AlekSi opened this issue Jun 23, 2015 · 2 comments

Comments

@AlekSi
Copy link

AlekSi commented Jun 23, 2015

http://ewencp.org/blog/golang-iterators/

@mantyr
Copy link
Owner

mantyr commented Jun 23, 2015

It is quite obvious. Example next:

@mantyr
Copy link
Owner

mantyr commented Jun 23, 2015

func TestIterBack(t *testing.T) {
    items := New()
    for i := 0; i < 100; i++ {
        items.Add(i, i)
    }

    i := 0
    for _, key := range items.Keys {
        item, ok := items.Get(key)
        if !ok {
            continue
        }
        if item == 10 {
            break
        }
        i++
    }
    if i != 10 {
        t.Errorf("Ooops, position error")
    }
}

Its Work.

@mantyr mantyr closed this as completed Jun 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants