Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

Some dance to remember...

Some dance to forget.

- Don Felder, Don Henley and Glenn Frey

 

The For statement provides a mechanism to execute a single block of statements in a loop. One or more optional initialization statements can be provided, and one or more optional "end of loop" statements can be provided. A Boolean Expression must be provided and is used to determine if the loop should continue to be executed. The following table shows the syntax for the For statement.

Aztec For Statement Syntax

 

♦ The expression must be a boolean expression.

♦ If provided, each 'Init Statement' is executed one time prior to the first evaluation of the boolean expression. They are executed in the order in which they are listed.

♦ The boolean expression is then evaluated and the specified block of statements is executed if true.

♦ After each execution of the statement block

♦ If provided, each 'End of Loop Statement' is executed in the order in which they are listed.

♦ The boolean expression is then re-evaluated, and the block is executed again if the boolean expression evaluates to true.

♦ This process is repeated until the expression evaluates to false or the code manually exits the loop ('break', 'return', etc.).

.♦ The two semilcolon delimiters must be used, even if the "Init Statement" and/or "End of Loop Statement" items are not used.

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

♦ An example script showing 'for' statement usage in a compiler method and a normal (run-time) method.

#===================================================================================================
# Example Script: For Statement
# Demonstrates the use of the 'for' statement in normal methods and compiler methods.
#===================================================================================================

# Source code is created dynamically at compile-time and compiled to create arrays with these names.
data<string> const VowelArrayName = 'VowelArray'
data<string> const ConsonantArrayName = 'ConsonantArray'

# Call the compiler method to create the vowel and consonant arrays.
CompilerCreateArrays()

#---------------------------------------------------------------------------------------------
# Compiler method to loop through character list and create vowel array and consonant array.
# It creates the lists dynamically in Aztec source code and then calls the LoadModule method
# to compile each of the two code strings as separate modules. That creates the Aztec arrays.
#---------------------------------------------------------------------------------------------
method compiler CompilerCreateArrays()
{
data<string> Char
data<string> CharCode
data<string> VowelArrayCode = "public data<string[]> " + VowelArrayName + " = { "
data<string> ConsonantArrayCode = "public data<string[]> " + ConsonantArrayName + " = { "
data<bool> VowelListEmpty = true
data<bool> ConsonantListEmpty = true

# Loop through all characters in the alphabet.
for ( Char = 'a' ; Char <= 'z' ; Char = CompilerStrInc(Char) )
{
# Determine if vowel or consonant and attach code for appropriate list.
if ( IsVowel(Char) )
{
if ( VowelListEmpty )
CharCode = "'" + Char + "'"
else
CharCode = ",'" + Char + "'"

# Add this item to the vowel array creation code and turn off empty flag.
CompilerStrAdd(@VowelArrayCode,CharCode)
VowelListEmpty = false
}
else
{
if ( ConsonantListEmpty )
CharCode = "'" + Char + "'"
else
CharCode = ",'" + Char + "'"

# Add this item to the consonant array creation code and turn off empty flag.
CompilerStrAdd(@ConsonantArrayCode,CharCode)
ConsonantListEmpty = false
}
}

# Attach the ending brace to each of the code strings.
CompilerStrAdd(@VowelArrayCode,'}')
CompilerStrAdd(@ConsonantArrayCode,'}')

# Now compile each of the source code strings to create the actual Aztec arrays.
CompilerLoadModule(VowelArrayCode,false)
CompilerLoadModule(ConsonantArrayCode,false)
}

# Compiler method to determine if a character is a vowel or consonant.
method<bool> compiler IsVowel(string Character)
{
data<bool> Result = false
data<string> UpperCase = CompilerStrUpr(Character)

if ( (UpperCase == 'A') | (UpperCase == 'E') | (UpperCase == 'I') |
(UpperCase == 'O') | (UpperCase == 'U') )
{
Result = true
}

return(Result)
}

#-----------------------------------------------------------------------------------
# Run-time entry point for the script. This method loops through each of the two
# array that were created with the above compile-time logic (VowelArray and
# ConsonantArray). It creates a formatted string for each to dump out the contents.
#-----------------------------------------------------------------------------------
method Main()
{
data<int> Count
data<string> ArrayString

# Loop through the vowel array and create a formatted string to write them out.
for ( Count = 1 ; Count <= VowelArray.Size() ; Count.Inc() )
{
if ( Count == 1 )
ArrayString = VowelArray[Count]
else
ArrayString.Add(", " + VowelArray[Count])
}

StdIO.Write("Vowel array contents: " + ArrayString)

# Loop through the consonant array and create a formatted string to write them out.
for ( Count = 1 ; Count <= ConsonantArray.Size() ; Count.Inc() )
{
if ( Count == 1 )
ArrayString = ConsonantArray[Count]
else
ArrayString.Add(", " + ConsonantArray[Count])
}

StdIO.Write("Consonant array contents: " + ArrayString)
}

Page UpPage DownCopyright © 2010-2017
Aztec Development Group
All Rights Reserved

Download Aztec