Aztec® Programming Language
Version 1.1 Alpha 2

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

Download Aztec

Search        Contact Us

But woman you're always on my mind....

Twenty four hours at a time.

- Toy Caldwell

 

The Repeat statement provides a mechanism to execute a single block of statements in a loop. It can be used standalone, in which case the loop is repeated forever, relying on the code inside the statement block to manually exit the loop (break, return, etc.) when appropriate. The Repeat statement can also be used together with the While or Until statements, which uses the Boolean Expression to determine when to terminate execution of the loop. The following table shows the syntax for the Repeat statement.

Aztec Repeat Statement Syntax

 

♦ For the ‘repeat’ statement used alone

♦ The specified block of statements is executed  forever. The code in the block must manually exit the loop (‘break’, ‘return’, ‘exit’, etc.).

♦ For the ‘repeat’ statement used with 'while'

♦ The ‘while’ expression must be a boolean expression.

♦ The specified block of statements is executed in a loop as long as expression is true.

♦ The loop is always executed at least once, as the boolean expression is evaluated at the bottom of the loop.

♦ For the ‘repeat’ statement used with 'until'

♦ The ‘until’ expression must be a boolean expression.

♦ The specified block of statements is executed in a loop as long as expression is false.

♦ The loop is always executed at least once, as the boolean expression is evaluated at the bottom of the loop.

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

♦ An example script showing 'repeat' statement usage (standalone and with while/until statements) in a compiler method and in a normal (run-time) method.

#===================================================================================================
# Example Script: Repeat Statement
# Demonstrates the use of the 'repeat' statement in normal methods and compiler methods, with
# and without 'while' or 'until'.
#===================================================================================================

# 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 = 'a'
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.
repeat
{
# 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
}

#-----------------------------------------------------------------------------
# Manually advance the char through the alphabet and check for exceeding 'z'.
# Since 'repeat' is used with no while/until, must manually exit loop.
#-----------------------------------------------------------------------------
Char = CompilerStrInc(Char)
if ( Char > 'z' )
{
break
}
}

# 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> Position
data<bool> KeepGoing
data<bool> ArrayDone
data<string> ArrayString

#-------------------------------------------------------------------------------
# Loop through the vowel array and create a formatted string to write them out.
# First guaranteed pass through loop is OK since array will never be empty.
#-------------------------------------------------------------------------------
Position = 1
KeepGoing = true
repeat
{
if ( Position == 1 )
ArrayString = VowelArray[Position]
else
ArrayString.Add(", " + VowelArray[Position])

# Manually increment the position and check for exceeding end of array.
Position.Inc()
if ( Position > VowelArray.Size() )
{
KeepGoing = false
}
}
while ( KeepGoing )

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

#------------------------------------------------------------------------------------
# Loop through the consonant array and create a formatted string to write them out.
# First guaranteed pass through loop is OK since array will never be empty.
#------------------------------------------------------------------------------------
Position = 1
ArrayDone = false
repeat
{
if ( Position == 1 )
ArrayString = ConsonantArray[Position]
else
ArrayString.Add(", " + ConsonantArray[Position])

# Manually increment the position and check for exceeding end of array.
Position.Inc()
if ( Position > ConsonantArray.Size() )
{
ArrayDone = true
}
}
until ( ArrayDone )

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

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

Download Aztec