2 Replies - 735 Views - Last Post: 17 April 2011 - 12:28 AM Rate Topic: -----

#1 csm23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 18-July 10

The For loop with arrays

Posted 15 April 2011 - 07:37 PM

I am teaching myself ruby and in one of my codes in Java I have this for loop
for(int i = 0; a[i] < x; i++);


I am unsure how to convert this code to ruby. I tried
for i in a[i]..x


but that produced some errors. Can someone please tell me how to convert the Java code above into ruby.
Is This A Good Question/Topic? 0
  • +

Replies To: The For loop with arrays

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,688
  • Joined: 13-March 10

Re: The For loop with arrays

Posted 16 April 2011 - 02:50 PM

for i in 1..8 do
    puts i
end


Was This Post Helpful? 0
  • +
  • -

#3 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: The For loop with arrays

Posted 17 April 2011 - 12:28 AM

Use each for iterating over Array. Almost no one uses "for" for this purporse. Also I'll advise you to read some books about what is Ruby, not to apply Java idioms(and stupid practices).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1