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

Android Kotlin for Java Developers Modelling Solitaire Finishing the Pieces

Shouldn't the answer be 012? Aren't 0 and 2 inclusive in the range?

Also the answer in the question 3 contradicts with the answer in the first question

2 Answers

andren
andren
28,558 Points
for (var i in 0..2) { 
    println(i) 
}

Will not produce "0 1 2" because it will actually produce an error. This error to be precise:

'var' on loop parameter is not allowed

I have not completed the "Kotlin for Java Developers" course yet, so I don't know if it is brought up in the course. But neither var nor val is supported when declaring an index variable for a for loop.

The third quiz code:

for (i in 23..25) { 
    println(i) 
}

Correctly omits the var keyword and therefore will produce "23 24 25" since it is an inclusive range as you correctly noted.

Thank you for confirming that up. I too noticed that difference but was not sure if that's not allowed in the for loop.