Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: Add JS Loop #182

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
do-while-loop
  • Loading branch information
thepravin committed Jan 18, 2024
commit 16d7840f65a7ea9e773ae34db97bb50c54801e6c
24 changes: 24 additions & 0 deletions JsLoops/do-while.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# JavaScript Do-While Loop

The `do-while` loop in JavaScript is a control flow statement that repeatedly executes a block of code as long as a specified condition is true. The key difference between a `do-while` loop and other loop structures is that it always executes the block of code at least once before checking the condition.

## Syntax

```javascript
do {
// code block to be executed
} while (condition);
```
## Use Cases
1) When you need to execute a block of code at least once, regardless of the initial condition.<br/>
2) When the loop's condition depends on the result of the code block's execution.

### Example
```javascript
let count = 0;

do {
console.log(`Count: ${count}`);
count++;
} while (count < 5);
```