Day ten in javascript .I shared the topics,what I learn today.
Do while
A do...while loop is like a while loop, but with one key difference:
It always executes the block at least once, even if the condition is false.
Syntax
do {
// code block to execute
} while (condition);
*The code block inside do { } runs first.
*Then, the condition is checked.
*If the condition is true, it repeats.
*If the condition is false, the loop stops.
eg:Runs at least once
let i = 10;
do {
console.log("Value of i is: " + i);
i++;
} while (i < 5);
output:
Value of i is: 10
eg:Normal Counting
let i = 1;
do {
console.log(i);
i++;
} while (i <= 5);
output:
1
2
3
4
5
Happy Coding...
Top comments (0)