Name

for Statement

Synopsis

for variable[, variable...] in expression [do]
code
end

Executes code once for each element in expression. Almost exactly equivalent to:

expression.each do |variable[, variable...]| code end

except that a for loop doesn’t create a new scope for local variables. A for loop’s expression is separated from code by the reserved word do, a newline, or a semicolon.

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.