Please can anyone explain to me step by step about this loop?

let sum = 0;

while (true) {

  let value = +prompt("Enter a number", '');

  if (!value) break; // (*)

  sum += value;

}
alert( 'Sum: ' + sum );

Please can anyone explain to me step by step about this loop? Especially the line below the prompt method.

the number entered in the prompt is stored in the variable called value and the if statement checks if the value variable is empty, if it is empty it break meaning it stops asking you to Enter a number then sums up all the number you have entered then display it back to you with the alert popup

1 Like

Thanks You explain it so well.

1 Like

You are welcome :wink: so happy to help

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.