11 Vote

Repeat Until Loop in JavaScript?

Question by Guest | Last update on 2021-06-13 | Created on 2013-03-06

I need a Repeat-Until loop in JavaScript, as it is possible, for example, in Delphi. So, I want to repeat something until a certain condition is met.

Is there such a loop in JavaScript? I've played around with different "Repeat" and "Until" combinations, but it is just not working.

ReplyPositiveNegative
3Best Answer7 Votes

The Repeat-Until-Loop in JavaScript is constructed with "do" and "while", for example like this:

var k = 0;

do { 
   k = k + 1;
} while (k < 10);

The variable "k" will be increased as long as "k" is smaller than 10.

So, contrary to Delphi, the condition is reversed: The loop is not executed until the condition is met, but until the condition is no longer met.
Last update on 2021-06-13 | Created on 2013-03-07

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.