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 Objective-C Basics (Retired) Functional Programming in C Control Flow - For Loops

why did he say int = 0?

Is it because 0 is the beginning and the beginning of executing a code always start at 0 when you trying to tell the sum of something and all other operators like multiplication, etc?

1 Answer

J.D. Sandifer
J.D. Sandifer
18,813 Points

It's a little hard to tell what you're asking because you left out the variable name.

If you're asking why int i = 0, then it's because array indexes start at 0 so that makes sense as the for loop is going through the array index by index. If you're asking why int sum = 0, then it's because yes, you want to start with 0 when you're going to sum a bunch of other numbers (e.g. from the array) so you get an accurate sum.