Jump Statements

Jump statements are used to unconditionally pass control. The following jump statements are available in the Fore.NET language:

The Break statement exits the nearest enclosing cycle statement.

The target of the Break statement is the end point of the nearest enclosing cycle statement. If this statement is not enclosed by a cycle statement, a compilation error occurs.

The Break statement cannot exit the Finally block. When this statement occurs within the Finally block, the target of the statement must be within the same Finally block. Otherwise, a compilation error occurs.

Example

Sub TestContinue();
Var
    b: boolean;
Begin
    Repeat
        //Code executed in cycle
        If MessageBox.Show("Result is incorrect. Repeat calculation?",
            "Confirmation", MessageBoxButtons.OKCancel) = DialogResult.OK Then
            Continue;
        Else
            Break
        End If;
        //Code executed after confirmation
    Until b;
End Sub;

The Continue statement starts a new iteration of the nearest enclosing cycle statement.

The target of the Continue statement is the end point of the nested statement block of the nearest enclosing cycle statement. If this statement is not enclosed by a cycle statement, a compilation error occurs.

The Continue statement cannot exit the Finally block. When this statement occurs within the Finally block, the target of the statement must be within the same Finally block. Otherwise, a compilation error occurs.

Example

Sub TestContinue();
Var
    b: boolean;
Begin
    Repeat
        //Code executed in cycle
        If MessageBox.Show("Result is incorrect. Repeat calculation?",
            "Confirmation", MessageBoxButtons.OKCancel) = DialogResult.OK Then
            Continue;
        Else
            Break
        End If;
        //Code executed after confirmation
    Until b;
End Sub;

The Return statement returns control to the point that called the procedure or function containing this statement. It is used in procedures, functions and properties. In procedures and the Set properties block the Return statement is used without an expression and results in exiting the procedure. In functions and the Get properties block the Return statement is used with an expression that is the result of the corresponding member.

Example

Class TestReturn
    i: integer;
    
    Sub Calculate();
    Begin
        //Procedure code
        If < Condition for exiting procedure > Then
            Return;
        End If;
    End Sub;
    
    Function Calculate1(): integer;
    Begin
        //Function code
        Return i;
    End Function;
    
    Property Value: integer
        Get
        Begin
            Return i
        End Get
        Set
        Begin
            
        End Set
    End Property;

End Class;

See also:

Fore.NET Language Guide