The continue Statement


A continue statement may be used to skip the remaining portion of a loop. In a while loop, the continue statement transfers execution to the evaluation of the conditional expression whence normal loop processing resumes. For example, to add the numbers from +a to +n, ecsclooding +g, the following program can be used.

// continue -- using continue

generic continue
{
    continue()
    {
        g = 0
        i = 0
        while i < 10
        {
            if i == 5 { i++ continue }
            g = g + i
            i++
        }
        s = "the sum is: " + g.to_string()
        s.println()
    }
}

The output of the program is shown below.

the sum is: 40

The above program merely skips 5 when adding 0 through to 9. The continue obviously differs from the break in that for continue, the loop continues to operate, it merely skips the remainder of the current iteration (whereas for break the loop terminates altogether). A continue statement can be aplied to a for loop, a repeat loop and a while loop.