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

Can't figure out this while loop

Note sure what I'm missing?

loop.rb
i = 0
while i > 5
  i += 1
end

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You just got the less than and greater than sign mixed up a bit! Try this:

i = 0
while i < 5
  i += 1
end

Thank you! The little things get me every time!

Michael Hulet
Michael Hulet
47,913 Points

This loop will never run. You initially set i to 0, but the loop will only run if i is greater than 5. My bet is that you meant less than. This will fix that:

i = 0
# Notice the reversed comparison sign
while i < 5
  i += 1
end

Thank you! The little things get me every time!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

To be fair, it's rarely the giant logic flaws that get us, is it? It's always the misspelled variable or missing quotation mark, etc! That's why it's so nice that people hang out here on the forums. Some days it's nice just to have an extra set of eyes! :)