<p>In Ruby:</p>

<pre><code>for i in A do
    # some code
end
</code></pre>

<p>is the same as: </p>

<pre><code>A.each do |i|
   # some code
end
</code></pre>

<p><code>for</code> is not a kernel method:</p>

<ul>
<li>What exactly is "<code>for</code>" in ruby</li>
<li>Is there a way to use other keywords to do similar things? </li>
</ul>

<p>Something like:</p>

<pre><code> total = sum i in I {x[i]}
</code></pre>

<p>mapping to:</p>

<pre><code> total = I.sum {|i] x[i]}
</code></pre>

```
for
```
is just syntax sugar for the
```
each
```
method. This can be seen by running this code:
```
```
for i in 1 do
end
```
```
This results in the error:
```
```
NoMethodError: undefined method `each' for 1:Fixnum
```
```