Looping with .each


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


What are the Instructions....??


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




text="this is a text"

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


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