Exiting a loop

Hello,

How can you exit a loop mid-way?:

while condition1

last if condition2

end

‘last’ doesn’t work.

Could someone tell me where this is documented?
It’s really hard to figure out much with the current Ruby documentation.

···


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Daniel Carrera wrote:

Hello,

How can you exit a loop mid-way?:

while condition1

last if condition2

end

‘last’ doesn’t work.

Could someone tell me where this is documented?
It’s really hard to figure out much with the current Ruby documentation.

break if condition2

break(value) if condition2

value is used as the value of the while statement.

Doc-ed in the Pickaxe chapter on Expressions. (But not the value
argument, which is a recently added feature.)

callcc do |end|
while condition1
end.call if condition2
end
end

···

Daniel Carrera (dcarrera@math.umd.edu) wrote:

Hello,

How can you exit a loop mid-way?:

while condition1

last if condition2

end


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Sigh.

Am I the only one who has a hard time browsing PickAxe?
I swear I care almost never find what I want promptly. Most of the
time I just stare at the section titles without a clue of which one might
have what I’m looking for. I click through them almost randomly and
eventually give up in frustration. Maybe it’s me, but I swear I’ve never
struggled so much with a reference book.

Thank you for your help. I do appreciate it.

···

On Sun, Mar 23, 2003 at 03:29:14PM +0900, Joel VanderWerf wrote:

break if condition2

break(value) if condition2

value is used as the value of the while statement.

Doc-ed in the Pickaxe chapter on Expressions. (But not the value
argument, which is a recently added feature.)


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

catch(:finished) do
while cond1
throw :finished if cond2
end
end

Gavin

···

On Tuesday, March 25, 2003, 6:28:29 AM, Eric wrote:

Daniel Carrera (dcarrera@math.umd.edu) wrote:

Hello,

How can you exit a loop mid-way?:

while condition1

last if condition2

end

callcc do |end|
while condition1
end.call if condition2
end
end

> Am I the only one who has a hard time browsing PickAxe?

You might grab a copy of Ruby in a Nutshell. Great reference. The
only gripe I have is that the class reference isn’t in alphabetical
order, but you get used to where stuff is. I don’t hav the PickAxe so
I can’t compare, but finding syntax other things hasn’t ever been a
problem here.

···

On Sun, 23 Mar 2003 15:38:10 +0900 Daniel Carrera dcarrera@math.umd.edu wrote:


Ryan Pavlik rpav@users.sf.net

“DEPLOY THE ROCKET BOAT!” - 8BT

Daniel Carrera wrote:

Sigh.

Am I the only one who has a hard time browsing PickAxe?
I swear I care almost never find what I want promptly. Most of the
time I just stare at the section titles without a clue of which one might
have what I’m looking for. I click through them almost randomly and
eventually give up in frustration. Maybe it’s me, but I swear I’ve never
struggled so much with a reference book.

I take it you mean the online version?

I always wondered why the links on RubyCentral don’t point to a version
with the frames “contents” and “jump targets”, which is included in the
downloadable version. I find the jump targets often help just as much as
the index at the back of the paper version.

Some online mirrors that do:
http://mattriffle.com/mirrors/ruby_book/
http://uic.rsu.ru/doc/programming/ruby/ProgrammingRuby/
ruby.no

(Are there any, slightly more “official” mirrors that use the frameset?)

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

I think it’s a ruse to get you to buy the paper version, which is much
easier to browse with a comprehensive contents and index, and a thumb-index
for the class reference. You get the pictures as well.

But if you pull down a local copy of the online version you can just grep
the html files…

Cheers,

Brian.

···

On Sun, Mar 23, 2003 at 03:38:10PM +0900, Daniel Carrera wrote:

Sigh.

Am I the only one who has a hard time browsing PickAxe?

Doc-ed in the Pickaxe chapter on Expressions. (But not the value
argument, which is a recently added feature.)

Sigh.

Am I the only one who has a hard time browsing PickAxe?
I swear I care almost never find what I want promptly.

You should take a look at:
http://www.ruby-lang.org/en/man-1.4/index.html

					FUKUMOTO Atsushi
					fukumoto@imasy.or.jp

I find the physical book much easier to use. It has a working index and
page numbers, which helps a lot.

Regards,
JJ

Be Kind, Be Careful, Be Yourself

···

On Sun, 2003-03-23 at 01:38, Daniel Carrera wrote:

On Sun, Mar 23, 2003 at 03:29:14PM +0900, Joel VanderWerf wrote:

break if condition2
Am I the only one who has a hard time browsing PickAxe?

Pickaxe is not a reference book, which mostly explains your
frustration. There’s a difference between your expectation (find
something quickly) and the reality (read it and learn).

I therefore suggest you read it chapter by chapter. Obviously, you
won’t remember everything, but you’ll remember vaguely where to find
things for future … er … reference.

Gavin

···

On Sunday, March 23, 2003, 5:38:10 PM, Daniel wrote:

break if condition2

break(value) if condition2

value is used as the value of the while statement.

Doc-ed in the Pickaxe chapter on Expressions. (But not the value
argument, which is a recently added feature.)

Sigh.

Am I the only one who has a hard time browsing PickAxe?
I swear I care almost never find what I want promptly. Most of the
time I just stare at the section titles without a clue of which one might
have what I’m looking for. I click through them almost randomly and
eventually give up in frustration. Maybe it’s me, but I swear I’ve never
struggled so much with a reference book.

Sigh.

Am I the only one who has a hard time browsing PickAxe?
I swear I care almost never find what I want promptly.

···

----- Original Message -----
From: “Daniel Carrera” dcarrera@math.umd.edu


Have you ever just read the whole thing, cover to cover? (The paper version
is nicer for that, of course.) It makes a difference.

The book is 564 pages. Page 277 and on are the class reference, appendices,
index, bibliography, etc. In other words, the “book” part of the book is
really less than half of the actual book. This might not be clear in the
online version. I’d say just read the whole “book” part, if you haven’t
already.

In my own personal experience, there are really just two places I use
anymore: the class reference (of course) and Chapter 18: The Ruby
Language. Chapter 18 sums up nearly everything you could ever want to know
(at least at your rather high level of understanding) in 39 lovely pages.
(It answers this question of yours, too.) And the next three chapters
answer you really deep questions, but in practice I rarely look at them.
It’s all in Chapter 18.

In the online version, click on the chapter heading “The Ruby Language”.

Aliasing question? Chapter 18.
Regex question? Chapter 18.
Keyword question? Chapter 18.
Snoopy ($&,$!,$$) question? Chapter 18.
/.*/ question? Chapter 18.

So how are you supposed to know this? I don’t know. But there is a hint at
the very beginning of Chapter 1, where the pragmatic programmers say that
they were using section 3 (which starts with Chapter 18) as they were
writing the rest of the book. And they reference it over and over at the
end of the Roadmap, too.

Oh, it’s a fine, fine book…

Chris

Daniel Carrera wrote:

···

On Sun, Mar 23, 2003 at 03:29:14PM +0900, Joel VanderWerf wrote:

break if condition2

break(value) if condition2

value is used as the value of the while statement.

Doc-ed in the Pickaxe chapter on Expressions. (But not the value
argument, which is a recently added feature.)

Sigh.

Am I the only one who has a hard time browsing PickAxe?
I swear I care almost never find what I want promptly. Most of the
time I just stare at the section titles without a clue of which one might
have what I’m looking for. I click through them almost randomly and
eventually give up in frustration. Maybe it’s me, but I swear I’ve never
struggled so much with a reference book.

Thank you for your help. I do appreciate it.

The book is a lot easier to find things in than the on-line reference.
When I’m using the on-line reference, I almost always operate from the
find tab, but with the book I tend to use the index. The index works
better, partially because the pages are of a reasonable size.

What’s wrong with a simple ‘break’? :slight_smile:

To swat a fly, use a flyswatter.

Hal

···

----- Original Message -----
From: “Gavin Sinclair” gsinclair@soyabean.com.au
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, March 24, 2003 11:46 PM
Subject: Re: exiting a loop

On Tuesday, March 25, 2003, 6:28:29 AM, Eric wrote:

Daniel Carrera (dcarrera@math.umd.edu) wrote:

Hello,

How can you exit a loop mid-way?:

while condition1

last if condition2

end

callcc do |end|
while condition1
end.call if condition2
end
end

catch(:finished) do
while cond1
throw :finished if cond2
end
end

If it is, it’s failed miserably… :slight_smile:

···

On Sunday, Mar 23, 2003, at 03:50 US/Central, Brian Candler wrote:

On Sun, Mar 23, 2003 at 03:38:10PM +0900, Daniel Carrera wrote:

Sigh.

Am I the only one who has a hard time browsing PickAxe?

I think it’s a ruse to get you to buy the paper version

It does now. :slight_smile:

···

On Sunday, Mar 23, 2003, at 02:31 US/Central, Kent Dahl wrote:

I always wondered why the links on RubyCentral don’t point to a version
with the frames “contents” and “jump targets”, which is included in the
downloadable version.

I therefore suggest you read it chapter by chapter. Obviously, you
won’t remember everything, but you’ll remember vaguely where to find
things for future … er … reference.

···

----- Original Message -----
From: “Gavin Sinclair” gsinclair@soyabean.com.au


Yes, but that works much better in the paper version. “Let’s see, that was
near the middle of the book, high on the left page…” as opposed to “Yeah,
I saw that on my screen…”

:slight_smile:

Chris

I note that one of the big online book stores has used copies available
for less than $10.00. Less than the cost of a CD. Less than a movie ticket
plus popcorn. Less than a stack of 50 blank CD-Rs.

There really is no excuse for NOT having a paper copy of the book.

···

On Mon, 24 Mar 2003 01:54:33 +0900, Gavin Sinclair wrote:

Pickaxe is not a reference book, which mostly explains your frustration.
There’s a difference between your expectation (find something quickly) and
the reality (read it and learn).

I therefore suggest you read it chapter by chapter. Obviously, you won’t
remember everything, but you’ll remember vaguely where to find things for
future … er … reference.

Gavin

catch(:finished) do
while cond1
while cond2
while cond3
while cond4

while cond99
throw :finished if cond100
end

end
end
end
end
end

Gavin :slight_smile:

···

On Tuesday, March 25, 2003, 5:15:19 PM, Hal wrote:

callcc do |end|
while condition1
end.call if condition2
end
end

catch(:finished) do
while cond1
throw :finished if cond2
end
end

What’s wrong with a simple ‘break’? :slight_smile:

To swat a fly, use a flyswatter.

It worked on me… at least, I got my employer to buy a copy :slight_smile:

I don’t suppose the original source is around? So for example we could take
references to “page 461” and turn them into hyperlinks?

Regards,

Brian.

···

On Sun, Mar 23, 2003 at 11:33:34PM +0900, Dave Thomas wrote:

On Sunday, Mar 23, 2003, at 03:50 US/Central, Brian Candler wrote:

On Sun, Mar 23, 2003 at 03:38:10PM +0900, Daniel Carrera wrote:

Sigh.

Am I the only one who has a hard time browsing PickAxe?

I think it’s a ruse to get you to buy the paper version

If it is, it’s failed miserably… :slight_smile: