# Problem in loop do

**URL:** <https://www.ruby-forum.com/t/problem-in-loop-do/192333>\
**Category:** Ruby\
**Created:** [July 28, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/problem-in-loop-do/192333 "2010-07-28T13:10:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [July 28, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/problem-in-loop-do/192333/1 "2010-07-28T13:10:15Z")

</div>

Hi  
please explain me with example in “loop do” , diffrence between “redo”  
and “next”.  
tnx

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [July 28, 2010, 1:56pm UTC](https://www.ruby-forum.com/t/problem-in-loop-do/192333/2 "2010-07-28T13:56:05Z")

</div>

On 28.07.2010 13:10, Amir E. wrote:

> please explain me with example in “loop do” , diffrence between “redo”  
> and “next”.

Why don’t you just write a small program and test it out for yourself?

Cheers

robert

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [July 28, 2010, 6:58pm UTC](https://www.ruby-forum.com/t/problem-in-loop-do/192333/3 "2010-07-28T18:58:42Z")

</div>

Robert K. wrote:

> On 28.07.2010 13:10, Amir E. wrote:
> 
> > please explain me with example in “loop do” , diffrence between “redo”  
> > and “next”.
> 
> Why don’t you just write a small program and test it out for yourself?
> 
> Cheers
> 
> robert

I wrote a small program , and I test for myself but the result for  
“next” and “redo” was same.  
now please help me .

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [July 28, 2010, 8:48pm UTC](https://www.ruby-forum.com/t/problem-in-loop-do/192333/4 "2010-07-28T20:48:32Z")

</div>

Amir E. wrote:

> I wrote a small program , and I test for myself but the result for  
> “next” and “redo” was same.  
> now please help me .

I’ve not been visiting here for very long, but I suspect people will be  
quicker/more inclined to help if you provide the program you’ve created  
to test the issue/question.

Play with the following code – run it and see what it does… uncomment  
the “next if i \< 3” line, run it, and see what it does… recomment the  
“next” line, uncomment the “redo” line, run it, and see what it does.

for i in 1…5  
puts 'current value of i is: ’ + i.to\_s  
#next if i \< 3;  
#redo if i \< 3;  
puts 'end of loop and i is: ’ + i.to\_s  
end

Additionally, a quick Google search of “ruby redo next” will turn up  
this link:

> **[Ruby - Loops](http://www.tutorialspoint.com/ruby/ruby_loops.htm)**
>
> Ruby Loops - Loops in Ruby are used to execute the same block of code a specified number of times. This chapter details all the loop statements supported by Ruby.
