Conditional Statements

Selection statements are used to change how a program executes depending on the value of an expression. There are the following conditional statements in Fore.NET:

The ?: conditional statement returns one of two values depending on the value of passed logical expression.

If an expression returns True, the expression followed by the ? character is calculated and becomes the result. If an expression returns True, the expression followed by the : character is calculated and becomes the result. In any case, only one of two expressions is returned.

Example

Imports System;
Imports System.Diagnostics;

Sub TestChoice();
Var
    RndObj: Random = New Random();
    i, j: Double;
Begin
    i := RndObj.NextDouble();
    j := RndObj.NextDouble();
    Debug.WriteLine(i > j ? "i>j" : "i<j");
End Sub;

The If statement is used to select how a program executes based on the value of a logical expression.

The statement is executed as follows:

Example

Sub TestIf();
Var
    a, b: Integer;
    c: Double;
Begin
    //...
    //Get the a, b, c values
    //...
    If (a > b) And (b > c) Then
        c := a - b;
    Elseif (a < b) And (b < c) Then
        c := b - a;
    Else
        c := (a + b) / 2
    End If;
    //...
End Sub;

The Select statement is used to select a list of statements for execution that have corresponding labels by comparing a label to the expression value.The header of the Select statement contains an expression calculation, which determines the executed statement block. The type of the expression in the statement header is named the governing type. The constant expressions in label lists should have values that can be implicitly converted to the governing type of the statement. If two or more label values are the same, a compilation error occurs.

The Select statement is executed as follows:

Example

Function TestSelect(a: integer): string;
Begin
    Select Case a
        Case 0Return "A=0";
        Case 1Return "A=1";
        Case 2Return "A=2";
        Else Return "A<>[0,2]";
    End Select;
End Function;

See also:

Fore.NET Language Guide