GeezerVison is showing github.com — Merge pull request #76 from sumn2u/master · encircleacity/javascript@cf6d822
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: en/SUMMARY.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
24 | 24 | * [Loops](loops/README.md) |
25 | 25 | * [For](loops/for.md) |
26 | 26 | * [While](loops/while.md) |
| 27 | + * [Do...While](loops/dowhile.md) |
27 | 28 | * [Functions](functions/README.md) |
28 | 29 | * [Declare](functions/declare.md) |
29 | 30 | * [Higher order](functions/higher_order.md) |
|
Collapse file
Copy file name to clipboard +35Lines changed: 35 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +# Do...While Loop |
| 2 | + |
| 3 | +The do...while statement creates a loop that executes a specified statement until the test condition evaluates to be false. The condition is evaluated after executing the statement. |
| 4 | +Syntax for do... while is |
| 5 | + |
| 6 | +```javascript |
| 7 | +do{ |
| 8 | + // statement |
| 9 | +} |
| 10 | +while(expression) ; |
| 11 | +``` |
| 12 | + |
| 13 | +Lets for example see how to print numbers less than 10 using `do...while` loop: |
| 14 | + |
| 15 | +``` |
| 16 | +var i = 0; |
| 17 | +do { |
| 18 | + document.write(i + " "); |
| 19 | + i++; // incrementing i by 1 |
| 20 | +} while (i < 10); |
| 21 | +``` |
| 22 | + |
| 23 | +>***Note***: `i = i + 1` can be written `i++`. |
| 24 | +
|
| 25 | + |
| 26 | +{% exercise %} |
| 27 | +Using a do...while-loop, print numbers between less than 5. |
| 28 | +{% initial %} |
| 29 | +var i = 0; |
| 30 | +{% solution %} |
| 31 | +var i = 0; |
| 32 | +do { |
| 33 | + i++; // incrementing i by 1 |
| 34 | +} while (i < 5); |
| 35 | +{% endexercise %} |