I figured it out, Its not actually exiting the loop but stops at a certain line because the variable at that line is not yet declared
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++)
{
var oFields = xfa.layout.pageContent(nPageCount, "field");
var nNodesLength = oFields.length;
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++)
{
if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit")
{
app.alert(oFields.item(nNodeCount).name);
if (fieldObject.rawValue!=null)
{
app.alert(fieldObject.rawvalue);
}
else
{
fieldObject.fillColor = "255,0,0"; // once this line is executed it exits the loop
errcnt++; //errcnt is not declared
}
}
}
}