Skip to content

Commit cf6d822

Browse files
committed
Merge pull request GitbookIO#76 from sumn2u/master
an example to show do while loop
2 parents e59994d + bd7da90 commit cf6d822

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

en/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [Loops](loops/README.md)
2525
* [For](loops/for.md)
2626
* [While](loops/while.md)
27+
* [Do...While](loops/dowhile.md)
2728
* [Functions](functions/README.md)
2829
* [Declare](functions/declare.md)
2930
* [Higher order](functions/higher_order.md)

en/loops/dowhile.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 %}

0 commit comments

Comments
 (0)