- Notifications
You must be signed in to change notification settings - Fork230
Loops: while and for#50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
15 commits Select commitHold shift + click to select a range
2b924a7 Merge pull request #1 from Sjesc/logical-operators
Sjesc1315688 Merge pull request #2 from javascript-tutorial/master
Sjesca14a4cc Traducción de while-for
Sjesc4b20b2a Arreglar errores de traducción
Sjesc2be400c Arreglar errores de traducción
Sjesc0505fed por -> en
tscandalittac5ee1bd fix ortografía
tscandalittadd2da13 fix tildes
tscandalitta51986c7 de el -> del
tscandalitta2d2105a Update task.md
tscandalittac54f0a8 Update solution.md
tscandalitta50275d7 Update solution.md
tscandalittaa419aab Update task.md
tscandalittaad4d41d Update task.md
tscandalitta617f0c4 múltiples correcciones
tscandalittaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
14 changes: 7 additions & 7 deletions1-js/02-first-steps/12-while-for/1-loop-last-value/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions1-js/02-first-steps/12-while-for/1-loop-last-value/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions1-js/02-first-steps/12-while-for/2-which-value-while/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,30 @@ | ||
| La tarea demuestra cómo las formas de sufijo y prefijo pueden llevar a diferentes resultados cuando son usadas en comparaciones. | ||
| 1. **Del 1al 4** | ||
| ```js run | ||
| let i = 0; | ||
| while (++i < 5) alert( i ); | ||
| ``` | ||
| El primer valor es `i = 1`,porque `++i`primero incrementa `i`y luego retorna el valor nuevo. Así que la primera comparación es`1 < 5`y el `alert`muestra `1`. | ||
| Entonces siguen `2, 3, 4…` --los valores son mostrados uno tras otro. La comparación siempre usa el valor incrementado, porque `++`está antes de la variable. | ||
| Finalmente, `i = 4`es incrementada a `5`,la comparación `while(5 < 5)`falla, y el bucle se detiene. Así que`5`no es mostrado. | ||
| 2. **Del 1al 5** | ||
| ```js run | ||
| let i = 0; | ||
| while (i++ < 5) alert( i ); | ||
| ``` | ||
| El primer valor es de nuevo`i = 1`.La forma del sufijo de`i++`incrementa `i`y luego retorna el valor *viejo*, así que la comparación`i++ < 5`usará`i = 0` (contrario a `++i < 5`). | ||
| Pero la llamada a`alert`está separada. Es otra declaración, la cual se ejecuta luego del incremento y la comparación. Así que obtiene el`i = 1` actual. | ||
| Luego siguen `2, 3, 4…` | ||
| Detengámonos en`i = 4`.La forma del prefijo`++i`lo incrementaría y usaría`5`en la comparación. Pero aquí tenemos la forma del sufijo `i++`.Así que incrementa `i`a `5`,pero retorna el valor viejo. Por lo tanto, la comparación es en realidad`while(4 < 5)` --verdadero, y el controlsigue a `alert`. | ||
| El valor `i = 5`es el último, porque el siguiente paso`while(5 < 5)`es falso. |
10 changes: 5 additions & 5 deletions1-js/02-first-steps/12-while-for/2-which-value-while/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions1-js/02-first-steps/12-while-for/3-which-value-for/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| **La respuesta: de `0 `a`4`en ambos casos.** | ||
| ```js run | ||
| for (let i = 0; i < 5; ++i) alert( i ); | ||
| for (let i = 0; i < 5; i++) alert( i ); | ||
| ``` | ||
| Eso puede ser fácilmente deducido del algoritmo de `for`: | ||
| 1.Ejecutar`i = 0`una vez antes de todo (comienzo). | ||
| 2.Comprobar la condición `i < 5`. | ||
| 3.Si `true` --ejecutar el cuerpo del bucle`alert(i)` y luego `i++`. | ||
| El incremento `i++`es separado de la comprobación de la condición(2).Es simplemente otra declaración. | ||
| El valor retornado por el incremento no es usado aquí, así que nohay diferencia entre`i++`y `++i`. |
10 changes: 5 additions & 5 deletions1-js/02-first-steps/12-while-for/3-which-value-for/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion1-js/02-first-steps/12-while-for/4-for-even/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,4 +8,4 @@ for (let i = 2; i <= 10; i++) { | ||
| } | ||
| ``` | ||
| Usamos el operador "modulo" `%`para conseguir el resto y comprobar la paridad. | ||
4 changes: 2 additions & 2 deletions1-js/02-first-steps/12-while-for/4-for-even/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,8 +2,8 @@ importance: 5 | ||
| --- | ||
| #Muestra números pares en el bucle | ||
| Usa el bucle`for`para mostrar números pares del`2`al `10`. | ||
| [demo] | ||
2 changes: 1 addition & 1 deletion1-js/02-first-steps/12-while-for/5-replace-for-while/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,7 @@ | ||
| ```js run | ||
| let i = 0; | ||
| while (i < 3) { | ||
| alert( `número ${i}!` ); | ||
| i++; | ||
| } | ||
| ``` | ||
6 changes: 3 additions & 3 deletions1-js/02-first-steps/12-while-for/5-replace-for-while/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions1-js/02-first-steps/12-while-for/6-repeat-until-correct/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions1-js/02-first-steps/12-while-for/6-repeat-until-correct/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
25 changes: 12 additions & 13 deletions1-js/02-first-steps/12-while-for/7-list-primes/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,28 @@ | ||
| Hay muchos algoritmos para esta tarea. | ||
| Usemos un bucle anidado. | ||
| ```js | ||
| Por cada ien el intervalo { | ||
| comprobar si itiene un divisoren 1..i | ||
| si tiene =>el valor no es un primo | ||
| si no =>el valor es un primo, mostrarlo | ||
| } | ||
| ``` | ||
| El código usando una etiqueta: | ||
| ```js run | ||
| let n = 10; | ||
| nextPrime: | ||
| for (let i = 2; i <= n; i++) { //por cada i... | ||
| for (let j = 2; j < i; j++) { //buscar un divisor.. | ||
| if (i % j == 0) continue nextPrime; //no es primo, ir al próximo i | ||
| } | ||
| alert( i ); //primo | ||
| } | ||
| ``` | ||
| Hay mucho lugar para la mejora. Por ejemplo, podríamos buscar por divisores desde`2`hasta la raíz cuadrada de`i`.Pero de todas formas, si queremos ser realmente eficientes para intervalos grandes, necesitamos cambiar el enfoque y confiar en matemáticas avanzadas y algoritmos complejos como [Criba cuadrática](https://es.wikipedia.org/wiki/Criba_cuadr%C3%A1tica), [Criba general del cuerpo de números](https://es.wikipedia.org/wiki/Criba_general_del_cuerpo_de_n%C3%BAmeros) etc. |
14 changes: 7 additions & 7 deletions1-js/02-first-steps/12-while-for/7-list-primes/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.