Use the while when you want a code block to repeat n times, using a simplier conditional checker.
<html>
<body>
<script>
number = 0
while (number < 10)
{
number++
}
alert(number)
</script>
</body>
</html>
While the conditional is true, the code block will be executed. Note that inside the block we are executing a code (number++) that will make us exit the loop (making the "number < 10" to be false in the future).