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,21 +8,24 @@ localeTitle: روبي للحلقات
للحلقات هي مجرد مثال واحد على التكرار أو التكرار على العناصر. في ما يلي مثال على حلقة for:
`for element in array do
puts element
end
`
```
for element in array do
puts element
end
```
هناك العديد من الطرق المختلفة التي يمكنك من خلالها تنفيذ حلقة أو حلقة في Ruby ، ​​مثال آخر مثل:
`element.each do |element|
puts element
end
`
```
array.each do |element|
puts element
end
```
هذا من شأنه أن يحقق نفس النتائج بالضبط كما سبق ذكره للحلقة ، ولكن مع ذلك أكثر إتقانا وأكثر كفاءة لأنه يستخدم أساليب Array المضمنة.
للذهاب خطوة أخرى ، يمكننا كتابة الحلقة أعلاه بالطريقة التالية:
`element.each do { |element| puts element }
`
```
array.each do |element| puts element end
```

View File

@@ -8,9 +8,9 @@ Ruby for循环用于循环或迭代许多元素并执行每个元素的代码块
for循环只是循环或迭代元素的一个例子。下面是for循环的示例
```
for element in array do
puts element
end
for element in array do
puts element
end
```
for循环也可以利用Range的方式来执行1..10 代表 1~10 包含 101...10 代表 1~10 不包含 10:
@@ -22,15 +22,15 @@ 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
```

View File

@@ -17,7 +17,7 @@ end
There are many many different ways in which you can execute a for loop or loop in Ruby, another such example would be:
```
element.each do |element|
array.each do |element|
puts element
end
```
@@ -27,5 +27,5 @@ This would achieve exactly the same results as the aforementioned for loop, it i
To go one step further, we can write the above loop in the following way:
```
element.each do { |element| puts element }
array.each do |element| puts element end
```

View File

@@ -8,25 +8,22 @@ Os loops forçados Ruby são usados para fazer loop ou iterar sobre vários elem
For loops são meramente um exemplo de loop ou iteração sobre elementos. Abaixo está um exemplo de um loop for:
```
for element in array do
puts element
end
for element in array do
puts element
end
```
Existem muitas maneiras diferentes nas quais você pode executar um loop ou iteração em Ruby, outro exemplo seria:
```
element.each do |element|
puts element
end
array.each do |element|
puts element
end
```
Isso alcançaria exatamente os mesmos resultados que o loop for mencionado anteriormente, mas é mais simples e mais eficiente, pois faz uso dos métodos incorporados do Array.
Para ir além, podemos escrever o loop acima da seguinte maneira:
```
element.each do { |element| puts element }
Desta forma, você tem cada elemento Array com o apelido passado entre os pipes: element. Este nome pode ser qualquer nome. Em seguida, você pode executar as operações nesse elemento específico, como no exemplo, imprimindo o elemento no console.
array.each do |element| puts element end
```

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
```

View File

@@ -8,22 +8,22 @@ Ruby para bucles se utilizan para hacer un bucle o iterar sobre una serie de ele
Para los bucles son simplemente un ejemplo de bucle o iteración sobre elementos. A continuación se muestra un ejemplo de un bucle for:
```
for element in array do
puts element
end
for element in array do
puts element
end
```
Hay muchas formas diferentes en las que puedes ejecutar un bucle for o bucle en Ruby, otro ejemplo sería:
```
element.each do |element|
puts element
end
array.each do |element|
puts element
end
```
Esto lograría exactamente los mismos resultados que el bucle anterior, sin embargo, es más limpio y eficiente, ya que hace uso de los métodos incorporados de Array.
Para ir un paso más allá, podemos escribir el bucle anterior de la siguiente manera:
```
element.each do { |element| puts element }
array.each do |element| puts element end
```
```