Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created April 8, 2020 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/3161595f423844bbcc3d14eaa720fd65 to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/3161595f423844bbcc3d14eaa720fd65 to your computer and use it in GitHub Desktop.
JavaScript - Los bucles while y do...while
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
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