# Why if executes two times?

**URL:** <https://rubytalk.org/t/why-if-executes-two-times/66048>\
**Category:** ruby-talk\
**Created:** [9 August 2012 08:03 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048 "2012-08-09T08:03:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [9 August 2012 08:03 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/1 "2012-08-09T08:03:11Z")

</div>

If I set a breakpoint at if statement, I see that the statement gets  
executed two times.. why so?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![ZhanGNer](https://avatars.discourse-cdn.com/v4/letter/z/8c91f0/32.png) [@ZhanGNer](https://rubytalk.org/u/ZhanGNer)\
**Post date:** [9 August 2012 09:07 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/2 "2012-08-09T09:07:41Z")

</div>

It shouldn't happened, may be due to IDE gives the illusion to you.

> **···**
>
> On Thu, Aug 9, 2012 at 4:03 PM, ajay paswan \<lists@ruby-forum.com\> wrote:
> 
> > If I set a breakpoint at if statement, I see that the statement gets  
> > executed two times.. why so?
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [9 August 2012 09:32 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/3 "2012-08-09T09:32:32Z")

</div>

ZhanGNer wrote in post #1071763:

> It shouldn't happened, may be due to IDE gives the illusion to you.

So how can I find the reason for illusion? or what I need to do now?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Matthew\_Kerwin](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/matthew_kerwin/32/1845_2.png) [@Matthew\_Kerwin](https://rubytalk.org/u/Matthew_Kerwin)\
**Post date:** [9 August 2012 09:52 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/4 "2012-08-09T09:52:41Z")

</div>

There are three questions I would need you to answer to be able to help further:  
\* What is the if statement in question?  
\* Is it in a reentrant position (e.g. a loop)?  
\* What are you using to set a breakpoint / debug the program?

> **···**
>
> On 9 August 2012 19:32, ajay paswan \<lists@ruby-forum.com\> wrote:
> 
> > ZhanGNer wrote in post #1071763:
> > 
> > > It shouldn't happened, may be due to IDE gives the illusion to you.
> > 
> > So how can I find the reason for illusion? or what I need to do now?
> 
> --  
> &nbsp;&nbsp;Matthew Kerwin, B.Sc (CompSci) (Hons)  
> &nbsp;&nbsp;[http://matthew.kerwin.net.au/](http://matthew.kerwin.net.au/)  
> &nbsp;&nbsp;ABN: 59-013-727-651
> 
> &nbsp;&nbsp;"You'll never find a programming language that frees  
> &nbsp;&nbsp;you from the burden of clarifying your ideas." - xkcd

---

<div class="post-metadata">

**Author:** ![ZhanGNer](https://avatars.discourse-cdn.com/v4/letter/z/8c91f0/32.png) [@ZhanGNer](https://rubytalk.org/u/ZhanGNer)\
**Post date:** [9 August 2012 10:18 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/5 "2012-08-09T10:18:12Z")

</div>

awesome  
may be you can paste your code if possible, and point out which line you  
set a breakpoint.

> **···**
>
> On Thu, Aug 9, 2012 at 5:52 PM, Matthew Kerwin \<matthew@kerwin.net.au\>wrote:
> 
> > On 9 August 2012 19:32, ajay paswan \<lists@ruby-forum.com\> wrote:  
> > \> ZhanGNer wrote in post #1071763:  
> > \>\> It shouldn't happened, may be due to IDE gives the illusion to you.  
> > \>  
> > \> So how can I find the reason for illusion? or what I need to do now?
> > 
> > There are three questions I would need you to answer to be able to help  
> > further:  
> > \* What is the if statement in question?  
> > \* Is it in a reentrant position (e.g. a loop)?  
> > \* What are you using to set a breakpoint / debug the program?
> > 
> > --  
> > &nbsp;&nbsp;Matthew Kerwin, B.Sc (CompSci) (Hons)  
> > &nbsp;&nbsp;[http://matthew.kerwin.net.au/](http://matthew.kerwin.net.au/)  
> > &nbsp;&nbsp;ABN: 59-013-727-651
> > 
> > &nbsp;&nbsp;"You'll never find a programming language that frees  
> > &nbsp;&nbsp;you from the burden of clarifying your ideas." - xkcd

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [13 August 2012 05:26 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/6 "2012-08-13T05:26:40Z")

</div>

> \* What is the if statement in question?  
> \* Is it in a reentrant position (e.g. a loop)?  
> \* What are you using to set a breakpoint / debug the program?

Just where the breakpoint is marked, is the place I set the breakpoint,  
and in the next statement also I set the break point, but it doesnt go  
to next till it gets executed two times, and yes I am using a  
debugger..with intelliJ idea and ruby.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [9 August 2012 15:49 UTC](https://rubytalk.org/t/why-if-executes-two-times/66048/7 "2012-08-09T15:49:26Z")

</div>

ZhanGNer wrote in post #1071768:

> awesome

Really!

see the program:

var=5  
if var == 10 #breakpoint here  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts("Variable is 10")  
end

I am using a breakpoint here 'pointed' and when I press resume, it comes  
again here, but when I program with java, this is not the case, it goes  
to the next step. I use intelliJ IDEA.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
