Aztec® Programming Language
Version 1.1 Alpha 2

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

Download Aztec

Search        Contact Us

Up with the sun... gone with the wind...

She always said I was lazy.

Leavin' my home... Leavin' my friends...

Runnin' when things get too crazy.

- Bob Seger

 

The Skip statement and Break statement each provide a mechanism to transfer control within a loop. The following table shows the syntax for the Skip and Break statements.

Aztec Skip and Break Statement Syntax

 

♦ For the 'skip' statement

♦ Stops execution and skips to the end of the loop currently being executed, skipping all of the remaining statements within the loop. All applicable "special" processing for the type of loop being executed is then performed, if applicable (execute end-of-loop statements for the 'for' statement and perform automatic increment for the 'iterate' statement) before being sent to the top of the loop for the next execution of the loop.

♦ The optional “# of loops” number (n) can be used to change the number of loops affected. It must be an integer constant. If the number is one, then we go to the end of the current loop (default). If two, we go to the end of the next outer loop, and so on.

♦ If no "# of loops" value is specified, the default value is one. If a value of zero is used, we skip to the bottom of the outermost loop, regardless of how many loops in question.

♦ For the 'break' statement

♦ Stops execution and breaks out of the loop currently being executed.

♦ The optional “# of loops” number (n) can be used to change the number of loops affected. It must be an integer constant. If the number is one, then we break out of the current loop (default). If two, we break out of the next outer loop as well, and so on.

♦ If no "# of loops" value is specified, the default value is one. If a value of zero is used, we break out of all loops, regardless of how many loops in question.

♦ The 'skip' and 'break' statements can only be used inside one of the loop statements, 'while', 'until', 'repeat', 'for' or 'iterate'.

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

#===================================================================================================
# Example Script: Skip and Break Statements
# Demonstrates the use of the 'skip' and 'break' statements within loop 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 characters in the alphabet, but stop when we reach 'p'. We're also
# going to skip over a few characters just to show the use of 'skip.
#---------------------------------------------------------------------------------
iterate ( Char in 'a'..'z' )
{
# Ignore certain characters for demo purposes by skipping to end of loop.
if ( (Char == 'd') | (Char == 'e') )
{
skip
}

# 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
}

if ( Char == 't' )
{
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> Count
data<bool> ListEmpty
data<string> ArrayString

# Loop through the vowel array and create a formatted string to write them out.
ListEmpty = true
iterate ( Count in 1..VowelArray.Size() )
{
# Ignore the last element for demonstration of 'break'.
if ( Count == VowelArray.Size() )
{
break
}

if ( ListEmpty )
ArrayString = VowelArray[Count]
else
ArrayString.Add(", " + VowelArray[Count])

ListEmpty = false
}

StdIO.Write("Partial vowel array contents: " + ArrayString)

# Loop through the consonant array and create a formatted string to write them out.
ListEmpty = true
iterate ( Count in 1..ConsonantArray.Size() )
{
# Ignore the first element for demonstration of 'skip'.
if ( Count == 1 )
{
skip
}

if ( ListEmpty )
ArrayString = ConsonantArray[Count]
else
ArrayString.Add(", " + ConsonantArray[Count])

ListEmpty = false
}

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

 

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

Download Aztec