Last active
May 24, 2019 00:19
-
-
Save alelazcano/3b7d50379f92578543663f0a262b6e92 to your computer and use it in GitHub Desktop.
Ejemplo muy básico de 'while' / 'for' en Javascript
This file contains 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
var alumnos = ['Mariana', 'Sebastián', 'Constanza']; | |
console.log("===== while ====="); | |
function listarAlumnos (lista) { | |
var n = 0; | |
while (n <= lista.length-1) { | |
console.log(n +" _ "+lista[n]); | |
n++ | |
} | |
} | |
listarAlumnos(alumnos); | |
console.log("===== for ====="); | |
function listarAlumnos2 (lista) { | |
for (var n=0; n <= lista.length-1; n++) | |
console.log(n+1 +" - "+ lista[n]); | |
} | |
listarAlumnos2 (alumnos); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var alumnos = ['Mariana', 'Sebastián', 'Constanza']; | |
console.log("===== while ====="); | |
function listarAlumnos (lista) { | |
var n = 0; | |
while (n <= lista.length-1) { | |
console.log(n +" _ "+lista[n]); | |
n++ | |
} | |
} | |
listarAlumnos(alumnos); | |
console.log("===== for ====="); | |
function listarAlumnos2 (lista) { | |
for (var n=0; n <= lista.length-1; n++) | |
console.log(n+1 +" - "+ lista[n]); | |
} | |
listarAlumnos2 (alumnos); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var alumnos = ['Mariana', 'Sebastián', 'Constanza']; | |
console.log("===== while ====="); | |
function listarAlumnos (lista) { | |
var n = 0; | |
while (n <= lista.length-1) { | |
console.log(n +" _ "+lista[n]); | |
n++ | |
} | |
} | |
listarAlumnos(alumnos); | |
console.log("===== for ====="); | |
function listarAlumnos2 (lista) { | |
for (var n=0; n <= lista.length-1; n++) | |
console.log(n+1 +" - "+ lista[n]); | |
} | |
listarAlumnos2 (alumnos);</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment