Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

nicole lumpkin
PLUS
nicole lumpkin
Courses Plus Student 5,328 Points

Why wouldn't the constant coordinatePoint need to be a var since it takes on a new value each time though the loop?

Wouldn't we we be reassigning coordinatePoint a new value each time around the loop? Each time we go around coordinatePoint takes on a new value and we then append said value into our accumulator array, results. FYI I'm a Python beginner. If this were coded in Python the variable coordinatePoint would be reassigned each time around the loop. So what is happening here!?! :)

nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

struct Point { let x: Int let y: Int func points(inRange range: Int = 1) -> [Point] { var results = Point

    let lowerBondOfXRange = x - range
    let upperBoundOfXRange = x + range

    let lowerBoundOfYRange = y - range
    let upperBoundOfYRange = y + range

    for xCoordinate in lowerBondOfXRange...upperBoundOfXRange {
        for yCoordinate in lowerBoundOfYRange...upperBoundOfYRange {
            let coordinatePoint = Point(x: xCoordinate, y: yCoordinate)
            results.append(coordinatePoint)
        }
    }

    return results
}

}