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

While Loop

it saying that my code took too long to load

loop.rb
i = 0

while i = 0
  i += 1
end

i = 0
while answer < 5
end

2 Answers

Casey Clayton
Casey Clayton
16,708 Points

That is happening because based on the code provided you are in an infinite loop.

It should be something like

i = 0

while i = 0
  i += 1
end

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

According to the code challenge however you just really need the first part as shown by Ace Motanya in his answer, the second part should be omitted completely as it was causing the infinite loop issue.

Due to the fact you that you had

# There is nothing in here to increment answer so it would just run forever. because answer will never equal 5.  
while answer < 5
end
Ace Motanya
Ace Motanya
31,756 Points
i = 0

while i < 5
  i += 1 
end