Skip to content

Commit 412ef2b

Browse files
committed
an example to show do while loop
1 parent e59994d commit 412ef2b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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)