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 trialRyan Maneo
4,342 PointsCome again?
While loops can have let after them to check for errors too? Omitted knowledge... Loops can be coupled with a try statement? Omitted knowledge. Where is the readFile function? Omitted knowledge. Someone please clarify and fill me in... I feel so confused all of a sudden!
Code I'm talking about: http://i.imgur.com/ld7PiUn.png
1 Answer
jakesager
12,023 PointsThat definitely isn't omitted knowledge. In the code you're referring to, he's simply calling the file.readLine() method, which from this context seems to return a boolean value depending on whether there are more lines. The reason he is assigning it to a constant is because it allows him to access the result of the function inside the while loop. While he didn't explicitly mention any of this in the video, it's common sense that you can use what is returned from a method in a while loop as the boolean value.
The readLine method doesn't need to be explicitly mentioned - it's coupled with the file class for use with files. We aren't specifically working with files in anything we are doing, and he used this purely as an example, which is why he didn't feel the need to dive further into the information.
Paul Karim
3,428 PointsPaul Karim
3,428 PointsHey jake I think what ryan meant was that we never used that kind of logic in the course for while loops or in the rest of the course so far. So if you're new to programming and only see while loops as being able to do things like while x > y etc seeing it binded like that might seem a bit odd.
Don't worry ryan it will make more sense in the future i'm sure :)
jakesager
12,023 Pointsjakesager
12,023 PointsPaul Karim Ah, understood. And yeah, don't worry too much about it Ryan. Through the rest of the courses, you'll gain exposure to many other abilities through the different functionalities of Swift and iOS development. If you see something you haven't before, just take it into account. If the question isn't answered later, ask it here :)