Break and continue statements

The break statement terminates a while or for loop completely. The continue statement terminates execution of the statements within a while or for loop and continues the loop in the next iteration. The following two examples demonstrate how these statements are used.

Note Both these statements violate the rules of structured programming but are nonetheless widely used in special cases.

function break4error(parmArray, x)
{
    var i = 0;
    var n = 0;
    while (i < 10)
    {
	if (isNaN(parmArray[x]))
    {
	print(parmArray[i].toString + “ is not numeric. Please repair
	and run again”);
	break;
    }
       n = n + parmArray[i];
       i++;
    }
    return n;
}

Modifying the above example, the continue statement would work as follows:

function break4error(parmArray, x)
{
    var i = 0;
    var n = 0;
    while (i < 10)
    {
	if (isNaN(parmArray[x]))
	{
	    print(parmArray[i].toString + “ is not numeric. Continuing with 
	    next number”);
	    i++;
	    continue;
	}
	    n = n + parmArray[i];
	    i++;
	}
	return n;
}