Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > DID YOU KNOW? -- break can return a value?

Reply
Thread Tools

DID YOU KNOW? -- break can return a value?

 
 
trans. (T. Onoma)
Guest
Posts: n/a
 
      10-18-2004
An interesting tidbit I pickup today. Did you know that break can return a
value from it's block?

a = loop do
break (1 + 1)
end

puts a #=> 4


T.
--
( o _ カラチ
// trans.
/ \ http://www.velocityreviews.com/forums/(E-Mail Removed)

I don't give a damn for a man that can only spell a word one way.
-Mark Twain



 
Reply With Quote
 
 
 
 
Dave Burt
Guest
Posts: n/a
 
      10-18-2004
"trans. (T. Onoma)" <(E-Mail Removed)> wrote...
> An interesting tidbit I pickup today. Did you know that break can return a
> value from it's block?
>
> a = loop do
> break (1 + 1)
> end
>
> puts a #=> 4
>


What platform gives that counterintuitive result? *grins*


 
Reply With Quote
 
 
 
 
zuzu
Guest
Posts: n/a
 
      10-18-2004
On Mon, 18 Oct 2004 11:49:23 +0900, Dave Burt <(E-Mail Removed)> wrote:
> "trans. (T. Onoma)" <(E-Mail Removed)> wrote...
> > An interesting tidbit I pickup today. Did you know that break can return a
> > value from it's block?
> >
> > a = loop do
> > break (1 + 1)
> > end
> >
> > puts a #=> 4
> >

>
> What platform gives that counterintuitive result? *grins*


by defining the variable "a" with code "loop", it is a Proc object, yes?

(sorry, i would test this myself except i'm away from my ruby console.)

(if so, i must simultaneously pronounce my dislike for imperative loop
structures, and my praise for ruby perceiving all code as in blocks /
procedures (functional/subroutine style).)

also, quite right dave, what gives with the "trailing off the edge of
a procedure 'return' " producing a "value" of 4? perhaps that's the
point; what exactly is going on when passing arguments into the break
function/keyword?

peace,
-z


 
Reply With Quote
 
Florian Frank
Guest
Posts: n/a
 
      10-18-2004
On 2004-10-18 21:39:40 +0900, zuzu wrote:
> also, quite right dave, what gives with the "trailing off the edge of
> a procedure 'return' " producing a "value" of 4? perhaps that's the
> point; what exactly is going on when passing arguments into the break
> function/keyword?


Whatever it may be, I am quite sure 1 + 1 is still equal to 2.

--
Florian Frank


 
Reply With Quote
 
trans. (T. Onoma)
Guest
Posts: n/a
 
      10-18-2004
On Monday 18 October 2004 09:10 am, Florian Frank wrote:
| On 2004-10-18 21:39:40 +0900, zuzu wrote:
| > also, quite right dave, what gives with the "trailing off the edge of
| > a procedure 'return' " producing a "value" of 4? perhaps that's the
| > point; what exactly is going on when passing arguments into the break
| > function/keyword?
|
| Whatever it may be, I am quite sure 1 + 1 is still equal to 2.

Yes, that's a typo, a would be 2, not 4. Strange how easy that is to
overlook!

T.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Why did my radio break? Bucky Breeder Computer Support 2 06-05-2010 11:39 PM
Coffee Break: When and How did you realize you are a betterprogrammer than you thought? pek Java 0 05-21-2008 04:02 PM
`if (!p ? i++ : 0) break;' == `if (!p){ i++; break;}' ? lovecreatesbea...@gmail.com C Programming 12 04-14-2008 07:59 AM
Did today's Windows updates break wireless?? The Celtic Warrior Wireless Networking 2 07-15-2004 10:41 PM
Did you know you can buy land on the moon? Morris Computer Support 33 11-30-2003 04:39 PM



Advertisments