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 trialpatrtoikua
1,871 PointsCan you guys explain this to me. Thanks.
Quiz question 4 of 5 Is the following a valid statement? while !gameOver { println(“keep playing”) }
patrtoikua
1,871 PointsI'm not sure if I understand you correctly so if we do the coding on Xcode we can use --> while !gameOver. Is it the same with ---> while game != gameOver. Do you think you can give me an example of coding of it, if not it's cool. Thanks.
Renato Nobre
5,805 PointsSo you need to define gameOver, in my case, I kept it simple, I defined gameOver = false, so when not gameOver, means it is equal true and then it would print keep playing.
var gameOver = false
while !gameOver {
println("keep playing")
gameOver = !gameOver
}
And after the println statement I defined gameOver to = !gameOver, that way it will change again to false and do an infinity loop.
Try running the code in a playground and see what happened. And them change the value of the var gameOver.
patrtoikua
1,871 PointsThank you so much. Now I understand it much better. I tried this doing this code too. Thanks again! =)
var gameOver = false
if !gameOver { println("keep playing") gameOver = !gameOver } else { println("GAME OVER") }
Renato Nobre
5,805 PointsYou Welcome, please give it a best if you found the answer clear, that way I will be able to help others.
=)
patrtoikua
1,871 PointsI would give it best answer but it won't let me do it. I don't know how. I am kinda new here on treehouse. Thanks! Appreciate!
1 Answer
Renato Nobre
5,805 PointsHi Jose, I remember when I did this quiz I got a little confused too. The point is, the code there is not complete, we don't know what is the value of gameOver, but what they want to understand there is a little bit of interpretation. Is indeed a valid statement, because while the game is not over you can keep playing. The use of the "!" symbol (simple that means not, in the code not gameOver) is totally correct, because it can be assign to a variable too.
Hope that helps
Any further questions fell free to contact me on my facebook or twitter, just check my profile!
(Try it now, I didn't put as an answer but as a comment)
Renato Nobre
5,805 PointsSo you need to define gameOver, in my case, I kept it simple, I defined gameOver = false, so when not gameOver, means it is equal true and then it would print keep playing.
var gameOver = false
while !gameOver {
println("keep playing")
gameOver = !gameOver
}
And after the println statement I defined gameOver to = !gameOver, that way it will change again to false and do an infinity loop.
Try running the code in a playground and see what happened. And them change the value of the var gameOver.
Renato Nobre
5,805 PointsRenato Nobre
5,805 PointsHi Jose, I remember when I did this quiz I got a little confused too. The point is, the code there is not complete, we don't know what is the value of gameOver, but what they want to understand there is a little bit of interpretation. Is indeed a valid statement, because while the game is not over you can keep playing. The use of the "!" symbol (simple that means not, in the code not gameOver) is totally correct, because it can be assign to a variable too.
Hope that helps
Any further questions fell free to contact me on my facebook or twitter, just check my profile!
Keep Up!