I have to terminate a while loop in javascript when a condition inside a inner for loop is met but this does not workas expected. below is my code snippet. it is not the actual script but a working one.
// Loop until Node appears
var nodeCreated = false;
var retries = 10;
while (retries > 0) {
//Thread.sleep(10000);
//sleep(i * 1000);
retries--;
//logger.addInfo("Waiting for node beeing created. " + retries.toString() + " retries left");
console.log("number of retries left " + retries);
//var nodes = nodeBeanPort.getNodes(c1);
const nodes = "2,3";
console.log(nodes.length);
if (nodes.length === 0) {
console.log("in equal to zero loop");
continue;
} else if (nodes.length > 0) {
// Found node
//logger.addInfo("Found Node in retry. " + retries.toString());
for (var nodeIndex in nodes) {
console.log("in for loop");
console.log("nodes: " + nodes);
var node = nodes[nodeIndex];
console.log("node: " + node);
console.log("nodeIndex: " + nodeIndex);
//logger.addInfo("Found Node " + node);
var x = 5;
if (x === 5) {
nodeCreated = true;
break;
}
}
//logger.addInfo("continuing loop ");
continue;
//break;
} else {
//for each(var node in nodes){
// logNode(node);
//}
nodeCreated = true;
//ctxt.setFailed("Could not narrow down to the newly created node. Found " +
// nodes.length.toString() + " nodes with this name");
break;
}
}
what i am looking for is that to end the script when below condition is true. like in this example:
if (x === 5) {
nodeCreated = true;
break;
}
I have also tried adding a lable but that does not work either.
Can someone suggest me how to solve this?