JavaScript - error en el while

 
Vista:
sin imagen de perfil

error en el while

Publicado por carlos (2 intervenciones) el 24/03/2023 01:54:18
//buenas tengo proble en el while y no comprendo el error

<html>
<head>
</head>
<body>
<script type="text/javascript">
var n=11;

while ( n >= 1)
{
document.write (n);
document.write ("<br>");
n=n +1;
}
</script>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

error en el while

Publicado por antonio (16 intervenciones) el 24/03/2023 16:07:52
Has realizado un bucle infinito el bucle se ejecuta mientras n sea mayor o igual a 1 y como mínimo vale 11 deberías en vez de sumar 1 restar 1 a la variable n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html>
<head>
</head>
<body>
<script type="text/javascript">
var n=11;
 
while ( n >= 1)
{
document.write (n);
document.write ("<br>");
n=n -1;
}
</script>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar