Euresys GenApi scriptsCoaxlink Programmer's Guide
}
function ContinueAndBreak() {
var i;
var sum = 0;
for (i = 0; i < 100; ++i) {
if (i === 3) {
continue;
} else if (i === 6) {
break;
} else {
sum += i;
}
}
assertEqual(0 + 1 + 2 + 4 + 5, sum);
}
ForLoops();
ForInLoops();
ForOfLoops();
ContinueAndBreak();
}
function Exceptions() {
var x;
var caught;
var finallyDone;
function f(action) {
x = 0;
caught = undefined;
finallyDone = false;
try {
x = 1;
if (action === 'fail') {
throw action;
} else if (action === 'return') {
return;
}
x = 2;
} catch (e) {
// Executed if a throw statement is executed.
assertEqual(1, x);
caught = e;
} finally {
// Executed regardless of whether or not a throw statement is
// executed. Also executed if a return statement causes the
// function to exit before the end of the try block.
finallyDone = true;
}
}
f('fail');
assertEqual(1, x);
assertEqual('fail', caught);
assert(finallyDone);
f('return');
assertEqual(1, x);
assert(!caught);
assert(finallyDone);
f();
assertEqual(2, x);
assert(!caught);
assert(finallyDone);
}
// Run tests
References();
Operators();
OuterFunction();
Loops();
Exceptions();
function assertEqual(expected, actual) {
if (expected !== actual) {
throw 'expected: ' + expected + ', actual: ' + actual;
29