Skip to content

Commit ba2d31e

Browse files
authored
Merge pull request #451 from gabifs/translate/while-for
Translate/while for
2 parents 5e54de6 + 902d511 commit ba2d31e

File tree

15 files changed

+204
-204
lines changed

15 files changed

+204
-204
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The answer: `1`.
1+
A resposta: `1`.
22

33
```js run
44
let i = 3;
@@ -8,18 +8,18 @@ while (i) {
88
}
99
```
1010

11-
Every loop iteration decreases `i` by `1`. The check `while(i)` stops the loop when `i = 0`.
11+
Cada iteração do laço diminui `i` em `1`. A verificação `while(i)` para o laço quando `i = 0`.
1212

13-
Hence, the steps of the loop form the following sequence ("loop unrolled"):
13+
Portanto, os passos do laço formam a seguinte sequência ("laço desenrolado"):
1414

1515
```js
1616
let i = 3;
1717

18-
alert(i--); // shows 3, decreases i to 2
18+
alert(i--); // mostra 3, diminui i para 2
1919

20-
alert(i--) // shows 2, decreases i to 1
20+
alert(i--) // mostra 2, diminui i para 1
2121

22-
alert(i--) // shows 1, decreases i to 0
22+
alert(i--) // mostra 1, diminui i para 0
2323

24-
// done, while(i) check stops the loop
24+
// fim, a verificação while(i) para o laço
2525
```

1-js/02-first-steps/13-while-for/1-loop-last-value/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# Last loop value
5+
# Último valor do laço
66

7-
What is the last value alerted by this code? Why?
7+
Qual é o último valor exibido por este código? Por quê?
88

99
```js
1010
let i = 3;
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
The task demonstrates how postfix/prefix forms can lead to different results when used in comparisons.
1+
A tarefa demonstra como as formas pós-fixa/prefixa podem levar a resultados diferentes quando usadas em comparações.
22

3-
1. **From 1 to 4**
3+
1. **De 1 a 4**
44

55
```js run
66
let i = 0;
77
while (++i < 5) alert( i );
88
```
99

10-
The first value is `i = 1`, because `++i` first increments `i` and then returns the new value. So the first comparison is `1 < 5` and the `alert` shows `1`.
10+
O primeiro valor é `i = 1`, porque `++i` primeiro incrementa `i` e depois retorna o novo valor. Então a primeira comparação é `1 < 5` e o `alert` mostra `1`.
1111

12-
Then follow `2, 3, 4…` -- the values show up one after another. The comparison always uses the incremented value, because `++` is before the variable.
12+
Depois seguem `2, 3, 4…` -- os valores aparecem um após o outro. A comparação sempre usa o valor incrementado, porque `++` está antes da variável.
1313

14-
Finally, `i = 4` is incremented to `5`, the comparison `while(5 < 5)` fails, and the loop stops. So `5` is not shown.
15-
2. **From 1 to 5**
14+
Finalmente, `i = 4` é incrementado para `5`, a comparação `while(5 < 5)` falha, e o laço para. Então `5` não é mostrado.
15+
2. **De 1 a 5**
1616

1717
```js run
1818
let i = 0;
1919
while (i++ < 5) alert( i );
2020
```
2121

22-
The first value is again `i = 1`. The postfix form of `i++` increments `i` and then returns the *old* value, so the comparison `i++ < 5` will use `i = 0` (contrary to `++i < 5`).
22+
O primeiro valor é novamente `i = 1`. A forma pós-fixa de `i++` incrementa `i` e depois retorna o valor *antigo*, então a comparação `i++ < 5` usará `i = 0` (ao contrário de `++i < 5`).
2323

24-
But the `alert` call is separate. It's another statement which executes after the increment and the comparison. So it gets the current `i = 1`.
24+
Mas a chamada `alert` é separada. É outra instrução que executa após o incremento e a comparação. Então ela obtém o `i = 1` atual.
2525

26-
Then follow `2, 3, 4…`
26+
Depois seguem `2, 3, 4…`
2727

28-
Let's stop on `i = 4`. The prefix form `++i` would increment it and use `5` in the comparison. But here we have the postfix form `i++`. So it increments `i` to `5`, but returns the old value. Hence the comparison is actually `while(4 < 5)` -- true, and the control goes on to `alert`.
28+
Vamos parar em `i = 4`. A forma prefixa `++i` incrementaria e usaria `5` na comparação. Mas aqui temos a forma pós-fixa `i++`. Então ela incrementa `i` para `5`, mas retorna o valor antigo. Portanto, a comparação é na verdade `while(4 < 5)` -- verdadeiro, e o controle segue para `alert`.
2929

30-
The value `i = 5` is the last one, because on the next step `while(5 < 5)` is false.
30+
O valor `i = 5` é o último, porque no próximo passo `while(5 < 5)` é falso.

1-js/02-first-steps/13-while-for/2-which-value-while/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ importance: 4
22

33
---
44

5-
# Which values does the while loop show?
5+
# Quais valores o laço while mostra?
66

7-
For every loop iteration, write down which value it outputs and then compare it with the solution.
7+
Para cada iteração do laço, escreva qual valor ele exibe e depois compare com a solução.
88

9-
Both loops `alert` the same values, or not?
9+
Ambos os laços exibem os mesmos valores via `alert`, ou não?
1010

11-
1. The prefix form `++i`:
11+
1. A forma prefixa `++i`:
1212

1313
```js
1414
let i = 0;
1515
while (++i < 5) alert( i );
1616
```
17-
2. The postfix form `i++`
17+
2. A forma pós-fixa `i++`
1818

1919
```js
2020
let i = 0;
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
**The answer: from `0` to `4` in both cases.**
1+
**A resposta: de `0` a `4` em ambos os casos.**
22

33
```js run
44
for (let i = 0; i < 5; ++i) alert( i );
55

66
for (let i = 0; i < 5; i++) alert( i );
77
```
88

9-
That can be easily deducted from the algorithm of `for`:
9+
Isso pode ser facilmente deduzido do algoritmo do `for`:
1010

11-
1. Execute once `i = 0` before everything (begin).
12-
2. Check the condition `i < 5`
13-
3. If `true` -- execute the loop body `alert(i)`, and then `i++`
11+
1. Executa uma vez `i = 0` antes de tudo (begin).
12+
2. Verifica a condição `i < 5`
13+
3. Se `true` -- executa o corpo do laço `alert(i)`, e depois `i++`
1414

15-
The increment `i++` is separated from the condition check (2). That's just another statement.
15+
O incremento `i++` é separado da verificação da condição (2). É apenas outra instrução.
1616

17-
The value returned by the increment is not used here, so there's no difference between `i++` and `++i`.
17+
O valor retornado pelo incremento não é usado aqui, então não há diferença entre `i++` e `++i`.

1-js/02-first-steps/13-while-for/3-which-value-for/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 4
22

33
---
44

5-
# Which values get shown by the "for" loop?
5+
# Quais valores o laço "for" mostra?
66

7-
For each loop write down which values it is going to show. Then compare with the answer.
7+
Para cada laço, escreva quais valores ele vai mostrar. Depois compare com a resposta.
88

9-
Both loops `alert` same values or not?
9+
Ambos os laços exibem os mesmos valores via `alert`, ou não?
1010

11-
1. The postfix form:
11+
1. A forma pós-fixa:
1212

1313
```js
1414
for (let i = 0; i < 5; i++) alert( i );
1515
```
16-
2. The prefix form:
16+
2. A forma prefixa:
1717

1818
```js
1919
for (let i = 0; i < 5; ++i) alert( i );

1-js/02-first-steps/13-while-for/4-for-even/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ for (let i = 2; i <= 10; i++) {
88
}
99
```
1010

11-
We use the "modulo" operator `%` to get the remainder and check for the evenness here.
11+
Usamos o operador "módulo" `%` para obter o resto e verificar a paridade aqui.

1-js/02-first-steps/13-while-for/4-for-even/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ importance: 5
22

33
---
44

5-
# Output even numbers in the loop
5+
# Exiba números pares no laço
66

7-
Use the `for` loop to output even numbers from `2` to `10`.
7+
Use o laço `for` para exibir números pares de `2` a `10`.
88

99
[demo]

1-js/02-first-steps/13-while-for/5-replace-for-while/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
```js run
44
let i = 0;
55
while (i < 3) {
6-
alert( `number ${i}!` );
6+
alert( `número ${i}!` );
77
i++;
88
}
99
```

1-js/02-first-steps/13-while-for/5-replace-for-while/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Replace "for" with "while"
5+
# Substitua "for" por "while"
66

7-
Rewrite the code changing the `for` loop to `while` without altering its behavior (the output should stay same).
7+
Reescreva o código alterando o laço `for` para `while` sem alterar seu comportamento (a saída deve permanecer a mesma).
88

99
```js run
1010
for (let i = 0; i < 3; i++) {

0 commit comments

Comments
 (0)