Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3026

Re: For loops trouble

X-FeedAbuse http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!talisker.lacave.net!lacave.net!not-for-mail
From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: For loops trouble
Date Sat, 16 Apr 2011 15:10:19 -0500
Organization Service de news de lacave.net
Lines 29
Message-ID <18d4507bb264800ed91298765159d5a1@ruby-forum.com> (permalink)
References <020937ce0d7f4e0fc8a6590932f71e15@ruby-forum.com>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1302984908 99085 65.111.164.187 (16 Apr 2011 20:15:08 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Sat, 16 Apr 2011 20:15:08 +0000 (UTC)
In-Reply-To <020937ce0d7f4e0fc8a6590932f71e15@ruby-forum.com>
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 381717
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <18d4507bb264800ed91298765159d5a1@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:3026

Show key headers only | View raw


Daniel Johnson wrote in post #993238:
> I am trying to translate a program I have in Java into ruby and having
> trouble translating this for loop
>    for(int i = 0; a[i] < x;i++)
> I tried this
>    for i in a[i]...x
> but it produce some errors. Any help will be appreciated. Thank you.

Ruby has a for-in loop:

a = [2, 4, 1, 9, 6]
x = 7

for num in a
  break if num > x
  puts num
end

But a for-in loop calls each(), so ruby programmers just use each() 
directly:

a.each do |num|
  break if num > x
  puts num
end

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

For loops trouble Daniel Johnson <zaldivar1841@gmail.com> - 2011-04-16 13:27 -0500
  Re: For loops trouble Josh Cheek <josh.cheek@gmail.com> - 2011-04-16 13:36 -0500
    Re: For loops trouble Josh Cheek <josh.cheek@gmail.com> - 2011-04-16 13:38 -0500
  Re: For loops trouble 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-16 15:10 -0500
  Re: For loops trouble Christopher Dicely <cmdicely@gmail.com> - 2011-04-16 15:30 -0500
  Re: For loops trouble botp <botpena@gmail.com> - 2011-04-16 20:04 -0500

csiph-web