Is there a do while equivalent in Java Script?

I'm somewhat familiar w/ VBA and I'm wondering what are the ways of doing this in JS.

2 Answers

2

There is

do { 
    // some code
} while (condition);

in C# - and this also exists in JavaScript - but I don't think this exists in UnityScript (which is the "JavaScript dialect" that you'll find in Unity).

Of course, you can work around this by using a while-loop, like:

var condition:boolean = true;
while (condition) {
    // some code
    condition = // what you'd usually have in the "while at the end"
}

Which is semantically equivalent with a do-while but not exactly as elegant.

do/while has existed in Unityscript since Unity 3.2.

var x = 0;
do {
    print (x++);
}
while (x < 5);