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 Build a Simple iPhone App with Swift Creating a Data Model Finishing Up Our Model

Mir Ali
Mir Ali
3,175 Points

Why can't we use for increment operator? for var i=0;i<factBook.factsArray.count;i+1

?

2 Answers

Enrique Munguía
Enrique Munguía
14,311 Points

Because the expression

i + 1 

results in a value of 1 if i starts at 0, but that value of 1 gets lost immediatly if it is not assigned to a variable. In order to increment i, the value must be assigned to i

i = i + 1

or its short equivalent

i++
Mir Ali
Mir Ali
3,175 Points

says error ++ is not a binary operator

Charles Zhang
Charles Zhang
2,032 Points

Because then it will not be random, it will display the facts in the order you put them in the facts array.