var sum = 0; while (true) { var value = +prompt("Введите число", ''); if (!value) break; // (*) sum += value; } alert( 'Сумма: ' + sum ); 
  • Endless cycle. But this is a bad code example. So it is not necessary to do - Andrey Kasyanov

1 answer 1

Hello.

In this code, while (true) means that the loop will run indefinitely, because it is executed as long as the condition is true , and in our case it will be true always.

To exit the loop, the following construction is provided: if (!value) break; i.e. if the user has not entered anything, the break statement exits the loop.

  • entered nothing , or entered 0, or not a number - Grundy