0

So I have a really frustrating build error I have been staring at for the past hour or two. It involves one of my functions in my linked list program. It thinks I have statements outside the function when they are clearly inside, and thinks the { : } ratio is off. Am I missing something really simple?

// Index returns the location of element e. If e is not present,
// return 0 and false; otherwise return the location and true.
func (list *linkedList) Index(e AnyType) (int, bool) {
        var index int = 0
        var contain bool = false
        if list.Contains(e) == false {
            return 0, false
        }
        for int i := 0; i < list.count; i++ {    \\175
            list.setCursor(i)
            if list.cursorPtr.item == e {
                index = list.cursorIdx
                contain = true
            }
        }
        return index, contain    \\182
}    \\183

Build errors

./lists.go:175: syntax error: unexpected name, expecting {
./lists.go:182: non-declaration statement outside function body
./lists.go:183: syntax error: unexpected }

I appreciate any help. Thank you.

0

1 Answer 1

4

Looks like it's all line 175's fault, should be

for i := 0; i < list.count; i++ {

note I removed int

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh thank you so much! := declares 'i' as an int already, so that was redundant. Thanks so much.
If you do want to declare types explicitly, the type goes after the variable in Go: play.golang.org/p/HPE35kl7ep

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.