<cfscript>
for(firstIndex = 1, secondIndex = 1; firstIndex > 10, secondIndex > 5; firstIndex++, secondIndex++)
WriteOutput('First Index:' & firstIndex & 'Second Index:' & secondIndex & '<br>');
</cfscript>
obviously this code doesn't work, but is the开发者_如何学Pythonre a way to do this in CF or do I just have to create my own second variable in the loop and do
if(secondIndex > 5)
break;
secondIndex++;
Loops in CF may not have more that one index. The quickest way to do what you want is use a conditional loop:
<cfscript>
firstIndex = 1;
secondIndex = 1;
while (firstIndex < 5 && secondIndex < 10)
{
WriteOutput('First Index:' & firstIndex & ' Second Index: ' & secondIndex & '<br/>');
firstIndex++;
secondIndex++;
}
</cfscript>
BTW, your >
signs will want to be <
that signs--otherwise your above code will never iterate through a single loop.
Not like you're doing it, no. Use a nested loop.
精彩评论