Syntax

Ruby Iterate with each Syntax

In Ruby, iterate with each: loops over every item — items.each { |item| puts item }

Quick Answer

Syntax
items.each { |item| puts item }
RubySyntax

Iterate with each

Code example
items.each { |item| puts item }

Loops over every item.

Learn More

How to iterate with each in Ruby

  1. Open your Ruby file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Ruby Iterate with each Syntax

Use items.each { |item| puts item }.

Related Syntax References

Frequently asked questions

What is the Ruby syntax for iterate with each?

Use this pattern: items.each { |item| puts item }

Can I copy this Ruby code example?

Yes. Use Copy code and adapt the example to your program.

Is this Ruby syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify