Use do while to loop through a block of code as long as i is less than 5 - Javascript Statement

Javascript examples for Statement:while

Description

Use do while to loop through a block of code as long as i is less than 5

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  ww w . j a  va2s . co  m*/
    var text = ""
    var i = 0;
    do {
        text += "<br>The number is " + i;
        i++;
    }
    while (i < 5);
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials