JAVASCRIPT BASICS
- Introduction to JavaScript
- Javascript Features
- JavaScript in HTML
- JavaScript Syntax
- Output in JavaScript
- JavaScript Variables
- Javascript let Keyword
- JS Literals and Keywords
- JavaScript Data Types
- JavaScript Operators
- JavaScript Events
- Javascript const Keyword
JAVASCRIPT FLOW CONTROL AND LOOPS
- JS if, else and else if
- JavaScript for Loop
- JS while and do-while loop
- JS Switch case
- JS break and continue
JAVASCRIPT ADVANCED
- JavaScript Strings
- JavaScript String Methods
- JavaScript Array
- JavaScript Regular Expression
- JavaScript Popup Boxes
- JavaScript Functions
- JavaScript Default Parameters
- JavaScript Rest Parameters
- JavaScript Arrow Function
- JavaScript Errors
- JavaScript Error Handling
- JavaScript Cookies
JAVASCRIPT OBJECT
- JavaScript Objects
- JavaScript User-defined Object
- JavaScript Boolean Object
- JavaScript Number Object
- JavaScript Math Object
- JavaScript Date Object
- JavaScript RegExp Object
JAVASCRIPT WEB API AND INTERFACES
Whenever you want to execute a certain statement over and over again you can use the JavaScript while loop to ease up your work. JavaScript while
loop lets us iterate the code block as long as the specified condition is true. Just like for Loop, the while
and do...while
loop are also used to execute code statements multiple times based on a condition.
The only difference between the while
loop and do...while
loop is that the do...while
loop will execute at least once because in do...while
loop the condition is checked after execution of code block.
JavaScript while
Loop: Syntax and Use
Below is the syntax for the while
loop:
while(condition)
{
// code statements
}
Let’s take an example to see the while
loop in action.
JavaScript while
Loop: Example
In this example, we are using while
loop, and the loop executes only if the specified condition is true.
let a = 9;
// while loop will be executed two times
while (a <= 10)
{
document.write("while executed <br>");
a++;
}
JavaScript do…while
Loop: Syntax and Use
Just like the while
loop, the do...while
loop lets you iterate the code block as long as the specified condition is true. In the do-while loop, the condition is checked after executing the loop. So, even if the condition is true or false, the code block will be executed for at least one time.
Below we have the syntax of the do...while
loop,
do
{
// code statements
}
while(condition)
JavaScript do...while
Loop: Example
Let’s take an example and see the do...while
loop in action.
let a = 10;
// will execute twice
do
{
document.write("do executed <br>");
a++;
}
while(a < 12)
In this tutorial, we explained the while
and do...while
loops used in the JavaScript.
3 thoughts on “JavaScript while Loop and do-while Loop”