BREAK 1g 2023 laplante@plcb.ca GOWEB/Language


title: “BREAK” author: “laplante@plcb.ca” date: 2023-01-01 version: “1.0.1”

section: “GOWEB/Language”

Description

The break statement is used to immediately terminate the execution of the innermost for loop in which it appears.
When executed, control flow continues with the statement following the loop.

When used with a label, break behaves similarly to a goto, allowing you to break out of a specific loop identified by the label.

⚠️ Restrictions:

This ensures that control flow remains structured and predictable.

Lexical Parser

T_BREAK T_SEMICOLON 
T_BREAK T_ID T_SEMICOLON 

Examples

Example of breaking out of a for loop with a switch statement inside:

res={{
    i := 1;

    for i < 5 {
        switch i {
            case 3:
                "3";
                break; // here, break exits the for loop, not the switch
            default:
                i;
        }
        i++;
    }
}}.
return 

res=123.