Aztec® Programming Language

Version 1.0 Alpha

Copyright © 2010-2013

Cold Spring® Development Group

All Rights Reserved

Download Aztec

Site Help

♦ Syntax

When Statement Syntax

 

♦ The 'branch' statement compares the expression against the list of values in the 'when' clauses. It goes top to bottom through the statement looking for a match in each 'when' clause, and executes the first block of statements where a match is found. It then exits the branch statement after the block is executed. Only one block is executed.

♦ At least one ‘when’ block is required.

♦ The ‘else’ block is optional, and is executed if no match is made in any of the 'when' clauses.

♦ The expression can be any primitive type (int, float, string or bool) and any type of user defined enumeration. It does not have to be a constant, but it must be a value (can not use references).

♦ The data type of each value specified in a ‘when’ clause must match the branch expression type.

♦ The ‘when’ clause supports a list of discrete values and/or ranges (Value1..Value2).

♦ Ranges go from a low limit to a high limit, inclusive, and can be any primitive data type or user defined enumeration.

♦ The 'branch' statement can only be used inside a "compiler" method or a "normal" method.

♦ Full source code examples showing 'branch' statement usage

   
# This constant uses a compiler method to initialize its value.
data<string> const  StartupName = CompilerConcatNames(3,'a','b','c')
  
# This method is used at compile-time and concatenates three names based on type id.
public compiler method<string> CompilerConcatNames(int Type, string Name1, string Name2, string Name3)
{
    data<string>    Return

    # Concatenate the string based on the type. This logic is done at compile-time.
    branch ( Type )
    {
        when ( 1 )
        {
            Return = Name1 + ' ' + Name2 + ' ' + Name3
        }
        when ( 2 )
        {
            Return = Name1 + ' ' + Name3
        }
        when ( 3 )
        {
            Return = Name3 + ", " + Name1
        }
        else
        {
            Return = CompilerStrUpr(Name3)
        }
    }

    return(Return)
}

# This class is used to startup the script.
public class Main from<Thread>
{
    public method Main()
    {
        Thread()						# Must invoke base constructor.
    }
public virtual method Run { data<string> Name # The 'branch' statement can also used strings and ranges. branch ( StartupName ) { when ( 'a c' ) { Name = "c, a" } when ( 'c, a' ) { Name = "a c" } when ( 'D'..'Z' ) { Name = StartupName.Lwr() } else { Name = "Aztec" } } Script().WriteLog("And the name is... " + Name) return } }

Page UpPage DownCopyright © 2010-2013
Cold Spring Development Group
All Rights Reserved

Download Aztec