-
-
Save DavidPeralvarez/3161595f423844bbcc3d14eaa720fd65 to your computer and use it in GitHub Desktop.
JavaScript - Los bucles while y do...while
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"> | |
<title>Curso de Javascript</title> | |
</head> | |
<body> | |
<script src="scripts.js"></script> | |
</body> | |
</html> |
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 i = 0; | |
while ( i < 10 ) { | |
i ++; // i = i + 1; | |
console.log( 'Aviso #' + i + ' David despierta de una vez.' ); | |
} | |
var diasSemana = [ 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado', 'domingo' ]; | |
i = 0; | |
while ( i < diasSemana.length ) { | |
console.log( i, diasSemana[i] ); | |
i ++; | |
} | |
var numeros = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], | |
suma = 0; | |
i = 0; | |
do { | |
suma += numeros[i]; | |
if ( suma > 10 ) { | |
break; | |
} | |
i ++; | |
} while ( i < numeros.length ); | |
console.log( suma ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment