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

Ruby Ruby Loops Ruby Loops The While Loop

Bug in code when exiting with the number 5

I think I see a bug in the video but don't think I should contact support.

If you try to run the while_number.rb file in workspace and enter the number 5, the code will break even though I think it should should only break with a number greater than 5.

I think that:

while answer < 5

should be changed to:

while answer <= 5

Hope it helps someone.

1 Answer

Garrett Carver
Garrett Carver
14,681 Points

Do you say "code will break" meaning that you got an error? Or do you mean that the while loop exits? In the video ( at 4:04), the instructions for the user do say "Enter a number greater than 5 to exit". So in that case using the following doesn't make sense: while answer <= 5

Hey Garrett, yeah I meant the while loop exists? I need to check myself with that phrase!

Yeah thats what I am saying Garrett, the code says that you should enter a number greater than 5 to exit but if you enter the number 5 it will also exit.