Skip to content

Commit

Permalink
Merge pull request GitbookIO#76 from sumn2u/master
Browse files Browse the repository at this point in the history
an example to show do while loop
  • Loading branch information
SamyPesse committed Apr 21, 2015
2 parents e59994d + bd7da90 commit cf6d822
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [Loops](loops/README.md)
* [For](loops/for.md)
* [While](loops/while.md)
* [Do...While](loops/dowhile.md)
* [Functions](functions/README.md)
* [Declare](functions/declare.md)
* [Higher order](functions/higher_order.md)
Expand Down
35 changes: 35 additions & 0 deletions en/loops/dowhile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Do...While Loop

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.
Syntax for do... while is

```javascript
do{
// statement
}
while(expression) ;
```

Lets for example see how to print numbers less than 10 using `do...while` loop:

```
var i = 0;
do {
document.write(i + " ");
i++; // incrementing i by 1
} while (i < 10);
```

>***Note***: `i = i + 1` can be written `i++`.

{% exercise %}
Using a do...while-loop, print numbers between less than 5.
{% initial %}
var i = 0;
{% solution %}
var i = 0;
do {
i++; // incrementing i by 1
} while (i < 5);
{% endexercise %}

0 comments on commit cf6d822

Please sign in to comment.