Javascript do while loop Statement

JavaScript do while loop will always be executing at least once, even if condition false, because condition works at the end of block of code so, block of code executed before the condition.



Syntax

do {
  code block to be executed
}
while (condition);


TUTORIAL

<html>
<body>
<button onclick="phpFunction()">Click Me</button>

<p id="result"></p>

<script>
function phpFunction() {
  var data = "";
  var i = 0;
  do {
    data += "<br>The count " + i;
    i++;
  }
  while (i < 10);
  document.getElementById("result").innerHTML = data;
}
</script>

</body>
</html>
OUTPUT

The count 0
The count 1
The count 2
The count 3
The count 4
The count 5
The count 6
The count 7
The count 8
The count 9

1 comment:

  1. What is the use of step statement for loop? and

    Can we use if statement in while loop?

    ReplyDelete

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...