Language
Version: 2.2.0
Categories
-
User Program Communication
-
Variables
-
Control Flow
-
Functions and Blocks
-
Object Oriented Programming
Control Flow
For Each in Ruby
The for-each loop iterates through every element in the array, without specifying size.
Syntax
array.each do |element|
#code to perform, on element
end
Notes
Each element is assigned a temporary iterator variable, declared in the for-each structure.
Elements are not accessed in any particular order.
Example
grades.each do |grade|
puts "Student grade: {grade}"
end