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
while-Loop
  • Loading branch information
thepravin committed Jan 18, 2024
commit a74c3cba08dca41f8a7ef4b7e970a18870ca519d
31 changes: 31 additions & 0 deletions JsLoops/while-loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# JavaScript While Loop

The JavaScript `while` loop is used to repeatedly execute a block of code as long as a specified condition is true. It is one of the fundamental control flow structures in JavaScript. <br/>
The while loop provides a flexible way to repeat a block of code based on a condition.

## Syntax

```javascript
while (condition) {
// code to be executed
}
```
### Example
```javascript
let count = 0;

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

console.log("Loop finished!");
```
## Infinite Loop
when using while loops to avoid creating infinite loops. An infinite loop occurs when the condition always evaluates to true, leading to continuous execution of the loop.
```javascript
// Caution: Infinite Loop
while (true) {
console.log("This is an infinite loop!");
}
```