Looping with .each


#1

I don't understando why and where should i use .each. Can someone explain to me? Thank you.


#2

@skillix,
What are the Instructions....??


#3

Let's start simply: write a loop .each to iterate in words and print using print , every word you find.


#4

@skillix,

==================================

text="this is a text"

puts "=== split into every-word =="
text.split(" ").each do | word |
     puts word
     end
puts "=== split into every-character =="
text.split("").each do | char |
     puts char
     end

==================================

If you have an Array as given data
you can directly use the each Method
giving you the possibility to manipulate each Array-Element.

myArray = [2,3,"string",2]
myArray.each do | element | 
              puts element
        end