Notes on Simple Loops and Iterators Suppose cond is some condition and code is a batch of code.
Bold words are keywords, and "each" is a method.

while cond [do]
  code
end
code while cond
begin
  code
end while cond
until cond [do]
  code
end
code until cond
begin
  code
end until cond

for i in 0..5 do
  code
end
(0..5).each do |i|
  code
end
(0..5).each {|i| code }
# { } with single-line iterators

In the last three loops, the two on the right are exactly the same,
and they define a scope for local variables, while the one on the left does not.
The vertical bars | i | define the loop variable.
This center and right ones are Ruby iterators.

A break terminates a loop.


Iterators from Methods on the Integer Class


Iterators from Range Objects


Iterators from arrays