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 trialJesús Camarena
7,280 PointsDetermining if it is Wrong: End Video Question. ( > VS. != )
So, for the question at the end of the video I initially went with != between remainingTries and Zero, I got the answer wrong. Tried it with > and passed. Now, I over think things through and I find both to be acceptable answers, but I can not find a reason why != would be wrong to use. Or am I wrong? Just need someone else's perspective.
1 Answer
jcorum
71,830 PointsIf you can guarantee that remainingTries will never be negative, then, yes, they would have the same effect.
Here's an example of what could go wrong with !=:
int x = 5;
while (x != 0) {
System.out.println(x);
x = x - 2;
}
(x != 0) will cause an infinite loop, where (x > 0) would not.
Jesús Camarena
7,280 PointsJesús Camarena
7,280 PointsAh, I can see how that may be a problem down the road. Thank you for sharing your time and thoughts. :)