Bringing values into a loop in Ruby -


This is almost certainly a duplicate, but I can not find the original - I do not have a search term to use it. Address . That's why I'm on the stackflow instead of Google :)

Anyway, here's my code:

  def is the title (say to) index = 0 words = Says. Do .each | Words | Until that word == "and" || "Or" || "Over" || "The" || "For" word.capitalize! End if index == 0 word.capitalize! End index + = 1 end = words .joint ("") end  

because the index has been declared before the loop, my if index == 0 is not Is working How do I know Ruby and how do I use my object index? Apart from this: What is it called?

using index == 0 is entirely your loop Your actual problem is probably in this line:

  words == "and" || "Or" || "Over" || "The" || "For"  

It's always like true ! What do you mean:

  ["and", "or", "over", "the", "for"]. Include? The word  

is a form that is used by every_with_index form, which you can use to:

  words. Each_with_index do Word, index |  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -