ArrayEach - How to stop execution?
How do you break out of the arrayEach function - stop execution?
break acts like continue
Code
<cfscript>
myArray = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
writeoutput("<h2>Loop</h2>");
for ( counter=1; counter<=arrayLen(myArray); counter++ ) {
thisElement = myArray[counter];
if ( counter == 5 ) {
continue;
}
if ( counter == 8 ) {
break;
}
outString = counter & " : " & thisElement & "<br>";
writeOutput(outString);
};
writeoutput("<h2>ArrayEach</h2>");
counter = 0;
arrayEach( myArray , function( thisElement ){
counter += 1;
if ( counter == 5 ) {
continue;
}
if ( counter == 8 ) {
break;
}
outString = counter & " : " & thisElement & "<br>";
writeOutput(outString);
});
</cfscript>
Output
Loop
1 : 1
2 : 2
3 : 3
4 : 4
6 : 6
7 : 7
ArrayEach
1 : 1
2 : 2
3 : 3
4 : 4
6 : 6
7 : 7
9 : 9 this should not be here
Answer would be much appreciated, no documentation.
