BREAK and CONTINUE Statements

BREAK and CONTINUE operate only within FOR, WHILE, and DO..WHILE loop statements.

The BREAK statement exits its loop.

The CONTINUE statement causes control to continue at the evaluation portion of its loop.

General Form

BREAK labelopt;
If no label is specified, implicitly refers to the innermost applicable loop.
CONTINUE labelopt;

Examples

i := 0;
while (1)
begin
    i := i + 1;
    print "i=" + i;
    if (i >= 10) 
        break;
    endif
end
Output:
1
2
3
4
5
6
7
8
9
10
i := 0;
while (1)
begin
    i := i + 1;
    if (i <= 5)
        continue;
    elseif (i >= 10) 
        break;
    endif
    print "i=" + i;
end
Output:
6
7
8
9
do
    begin
        i := i + 1;
        if (i <= 5)
            continue;
        endif
        print "i=" + i;
    end
while (i < 10);
 
j := 0;

outer:
while ( 1 )
begin
    print "in outer loop";

    local i;
    for(i := 0; i < 5; i++ )
    begin
        print "i: " + i + ", j: " + j;
        if (j >= 8)
            break outer;
        endif
    end
end
  Output: