|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
greetings!
i have the following structure <cfloop ...> loop1 <cfloop ....> loop2 <cfloop ...> loop3 if... else <cfbreak> </cfloop> <cfloop ...> loop4 if... else <cfbreak> </cfloop> </cfloop> </cfloop> my question is if the loop3 if condition is not satisfied where the <cfbreak> dumps me? it seems like it terminates all the loops including loop1 and loop2. if i want to terminate only loop3 and continue with the others what do i need to do? thanks for the help in advance... |
|
#2
|
|||
|
|||
|
I would *think* it should only terminate the current loop and return processing to "loop 2". But I'm not sure, it could also dump you out of the entire loop series.
However, if you are running four nested loops you may well be missing a more optimal solution to your problem. I'm not sure I've ever seen a situation that required four nested loops to solve.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
for some reason it breaks out from every single loop. is there a way to just terminate the loop3? i wish i had less loops, but i couldn't come up with a better solution
|
|
#4
|
|||
|
|||
|
From my recollections, I've run embedded loops that broke on a specific condition and it did not stop the outer loops. To test, I just wrote a simple piece of code.
I have 2 loops. The first loop counts from 1 - 10. With each iteration a second, embedded loop counts down from 10 - 1. If the first loop equals 5, the embedded loop breaks. It worked fine--number five didn't run the embedded loop, but every number did. Here's the code I ran: <cfloop index="loopCount" from="1" to="10" step="1"> #loopCount# - <cfloop index="reverseCount" from="10" to="1" step="-1"> <cfif loopCount IS 5><cfbreak></cfif> #reverseCount#, </cfloop><br> </cfloop> And the results: 1 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 4 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 5 - 6 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 8 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10 - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, |
|
#5
|
|||
|
|||
|
cfbreak definitely only breaks out of the current loop. If it's jumping completely out, maybe the structuring of your loops and/or conditions are not correct.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > <cfbreak> question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|