Files
freeCodeCamp/guide/russian/ruby/ruby-for-loop/index.md
2019-02-18 12:32:17 -08:00

30 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Ruby For Loops
localeTitle: Цикл For в Ruby
---
## Цикл For в Ruby
Цикл for в Ruby используется для повторения блока кода несколько раз. Этот цикл часто используются для перебора элементов массива. См. Раздел « [Массивы в Ruby»](https://github.com/freeCodeCamp/guides/blob/master/src/pages/ruby/ruby-arrays/index.md) .
Перебор элементов массива это всего лишь один из примеров использования цикла for:
```
for element in array do
puts element
end
```
В Ruby сучетсвют другие циклы и итераторы которыми можно заменить for. Например:
```
element.each do |element|
puts element
end
```
Результат выполнения этого блока кода будет идентичен примеру с циклом for, но выглядит более аккуратно так как использует встроенный метод Array.
Также этот пример можно переписать в одну строку:
```
element.each do { |element| puts element }
```