Fix ruby for-loops examples (#30309)

* Fix ruby for-loops examples

* Fix alignment

* fix: corrected array.each do syntax

* fix: corrected array.each do syntax

* fix: correct array.each do syntax

* fix: corrected array.each do syntax

* fix: correct array.each do syntax

* fix: correct array.each do syntax
This commit is contained in:
Alexander Dervish
2019-03-29 02:27:39 +02:00
committed by Randell Dawson
parent c606946c5c
commit 0191cb2eb4
6 changed files with 44 additions and 44 deletions

View File

@@ -8,22 +8,22 @@ localeTitle: Цикл For в Ruby
Перебор элементов массива это всего лишь один из примеров использования цикла for:
```
for element in array do
puts element
end
for element in array do
puts element
end
```
В Ruby сучетсвют другие циклы и итераторы которыми можно заменить for. Например:
```
element.each do |element|
puts element
end
array.each do |element|
puts element
end
```
Результат выполнения этого блока кода будет идентичен примеру с циклом for, но выглядит более аккуратно так как использует встроенный метод Array.
Также этот пример можно переписать в одну строку:
```
element.each do { |element| puts element }
array.each do |element| puts element end
```