myArray = [
"a",
"b",
"c"
];
// For Loop By index
for( i = 1; i <= arrayLen( myArray ); i++ ) {
writeOutput( myArray[ i ] );
}
// By For
for( currentIndex in myArray ) {
writeOutput( currentIndex );
}
// By arrayEach()
myArray.each( ( Any element, Any index ) => {
writeOutput( element & " : " & index );
} );
Bx:loop over an Array
Array Loop
<bx:set myArray = [
"a",
"b",
"c"
] >
<!--- By index --->
<bx:loop index="i" from="1" to="#arrayLen( myArray )#">
<bx:output>#myArray[ i ]#</bx:output>
</bx:loop>
<!--- By array --->
<bx:loop index="currentIndex" item="currentItem" array="#myArray#">
<bx:output>#currentIndex#</bx:output>
<bx:output>#currentItem#</bx:output>
</bx:loop>
Loop over a Struct (Script Syntax)
Struct Loop
myStruct = {
NAME : "Tony",
STATE : "Florida"
};
// By struct
for( currentKey in myStruct ) {
writeOutput( "<li>#currentKey# : #myStruct[ currentKey ]#</li>" );
}
// By structEach()
myStruct.each( ( Any key, Any value ) => {
writeOutput( "<li>#key# : #value#</li>" );
} );
Bx:loop over a Struct
Loop over a Struct using the collection and item arguments of bx:loop.
<!--- Define our struct --->
<bx:set myStruct = {
NAME : "Tony",
STATE : "Florida"
} >
<!--- By struct --->
<bx:loop item="currentKey" collection="#myStruct#">
<bx:output><li>#currentKey# : #myStruct[ currentKey ]#</li></bx:output>
</bx:loop>
Bx:loop over a Struct
Loop over a Struct using the collection, index and item arguments of bx:loop.
<!--- Define our struct --->
<bx:set myStruct = {
NAME : "Tony",
STATE : "Florida"
} >
<!--- By struct --->
<bx:loop item="currentItem" collection="#myStruct#" index="currentKey">
<bx:output><li>#currentKey# : #currentItem#</li></bx:output>
</bx:loop>
Loop over a List (Script Syntax)
List Loop
// Define our list
myList = "a, b, c";
// By array
for( item in listToArray( myList, "," ) ) {
writeOutput( item );
}
// By listEach()
myList.each( ( Any element, Any index ) => {
writeOutput( element & " : " & index );
}, "," );
Bx:loop over a List
List Loop
<!--- Define our list --->
<bx:set myList = "a, b, c" >
<!--- By list --->
<bx:loop index="item" list="#myList#">
<bx:output>#item#</bx:output>
</bx:loop>
<!--- By array --->
<bx:loop index="currentIndex" array="#listToArray( myList, "," )#">
<bx:output>#currentIndex#</bx:output>
</bx:loop>
Pre-Condition Loop This form of loop evaluates a single condition at the beginning of each iteration, and continues to loop whilst the condition is true
while (condition) {
// statements
}
Do While Loop (Script Syntax)
Post-Condition Loop This form of loop evaluates a single condition at the beginning of each iteration, and continues to loop whilst the condition is true