# Odd break behavior?

**URL:** <https://www.ruby-forum.com/t/odd-break-behavior/70105>\
**Category:** Ruby\
**Created:** [February 18, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105 "2006-02-18T17:43:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://www.ruby-forum.com/u/Thomas_E_Enebo)\
**Post date:** [February 18, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105/1 "2006-02-18T17:43:47Z")

</div>

Run the code snippet below:

class A  
def outer  
inner do  
break  
end  
end

def inner  
while true  
yield  
end  
puts “Should never appear”  
end  
end

[‘something’].each do  
A.new.outer  
puts “1”  
end

A.new.outer  
puts “2”

Then comment out the something each block and rerun it. The first  
run will look like:  
1  
2

The second run will look like:  
Should never appear  
2

For consistencies sake, I would have expected the first run to look  
like:  
1  
Should never appear  
2

By virtue of previously calling outer in a block the second call to  
outer  
now has different behavior (even though to me they look totally  
unrelated).  
Can someone explain why this is?

-Tom

---

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://www.ruby-forum.com/u/Thomas_E_Enebo)\
**Post date:** [February 18, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105/2 "2006-02-18T18:05:00Z")

</div>

Hi,

In message “Re: Odd break behavior?”  
on Sun, 19 Feb 2006 01:40:48 +0900, Thomas E Enebo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

| Run the code snippet below:

It seems to be a bug. Thank you for finding it. It’s too complex to  
fix it in a minute.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://www.ruby-forum.com/u/Thomas_E_Enebo)\
**Post date:** [February 18, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105/3 "2006-02-18T18:17:06Z")

</div>

On Sun, 19 Feb 2006, Yukihiro M. defenestrated me:

> In message “Re: Odd break behavior?”  
> on Sun, 19 Feb 2006 01:40:48 +0900, Thomas E Enebo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> | Run the code snippet below:
> 
> It seems to be a bug. Thank you for finding it. It’s too complex to  
> fix it in a minute.

I am trying to determine the proper behavior to fix break in jruby.  
Was what I expected the proper behavior?

-Tom

---

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://www.ruby-forum.com/u/Thomas_E_Enebo)\
**Post date:** [February 18, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105/4 "2006-02-18T19:05:49Z")

</div>

> > > > > “Y” == Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

Y\> It seems to be a bug. Thank you for finding it. It’s too complex to  
Y\> fix it in a minute.

moulon% diff -u eval.c~ eval.c  
— eval.c~ 2005-12-20 14:41:47.000000000 +0100  
+++ eval.c 2006-02-18 18:46:29.000000000 +0100  
@@ -752,7 +752,7 @@  
#define BLOCK\_LAMBDA 2

static struct BLOCK \*ruby\_block;  
-static unsigned long block\_unique = 0;  
+static unsigned long block\_unique = 1;

#define PUSH\_BLOCK(v,b) do {   
struct BLOCK \_block;   
moulon%

no ?

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://www.ruby-forum.com/u/Thomas_E_Enebo)\
**Post date:** [February 20, 2006, 2:01am UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105/5 "2006-02-20T02:01:45Z")

</div>

Hi,

In message “Re: Odd break behavior?”  
on Sun, 19 Feb 2006 02:14:37 +0900, Thomas E Enebo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

| I am trying to determine the proper behavior to fix break in jruby.  
|Was what I expected the proper behavior?

“break” should always terminate the lexically innermost loop or block.  
In this case, invocation of “inner” should have been terminated. A  
bug cause termination of while loop (the closest loop in dynamic call  
graph) in the definition of “inner” erroneously.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://www.ruby-forum.com/u/Thomas_E_Enebo)\
**Post date:** [February 20, 2006, 1:52am UTC](https://www.ruby-forum.com/t/odd-break-behavior/70105/6 "2006-02-20T01:52:36Z")

</div>

Hi,

In message “Re: Odd break behavior?”  
on Sun, 19 Feb 2006 03:02:04 +0900, ts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|-static unsigned long block\_unique = 0;  
|+static unsigned long block\_unique = 1;

| no ?

Yes! You must be a genius. Thank you.

```
						matz.

```
