JavaScript Lessons

JavaScript Do While Loop Examples You Can Use

See how the JavaScript do while loop works with practical examples, and learn when to use it so your code repeats actions reliably.

Serhat ALPASLAN1 min read

javascript do while loop

Just like the while loop we covered in the previous lesson, the JavaScript do while loop is used when you don’t know in advance how many times the loop needs to run. In a do while, the condition comes at the end. For this reason, a do while loop will run at least once before it reaches the condition.

Syntax

do { 
   // operations to perform 
} 
while (koşul)

Let’s start with some JavaScript do while loop examples.

var rakam = 1;
do
{
console.log(rakam++);
}
while ( rakam <= 5 );

In the example above, the do while loop will continue until the rakam variable is equal to 5.

Share it if it helped

Write a comment