http://purl.org/tcl/home/man/tcl8.4/TclCmd/continue.htm ---- [LES]: Suppose the following code: foreach i $List1 { foreach j $List2 { if [some condition] {continue} eval {blah blah blah} } } [Continue] interrupts the foreach j loop. But what if I wanted it to break the foreach i loop? Place the [[foreach i]] command in a proc and use [return] instead of [continue]. [Lars H]: Or use [breakeval] as follows foreach i $List1 { breakeval-aware foreach j $List2 { if {[some condition]} then { breakeval {continue} ; # Break out of j loop, do a continue for the i loop. } eval {blah blah blah} } } [MG] April 20th 2005 - In [PHP], [continue] (and [break]) accept an argument that tells it how many nesting levels to continue/break for, slightly-similar to return's -code option. How hard would it be to add something like that into Tcl? Since neither [break] nor [continue] accept any arguments right now, as long as it defaulted to 1 it would have total backwards-compatability, and would, IMHO, be more "natural" than the above. [schlenk] Did you try [return] -code continue -level ... [LES]: These suggestions all involve creating yet another proc for my code, which is not really what I was looking for. I was indeed thinking of [PHP]'s continue/break argument, as [MG] mentioned. I asked the question in the first place because I already have a solution, but it forces me to add more code to an already very long proc that I am trying to do some liposuction on. Some sort of "loop depth argument" would help me make it shorter. Anyway, here is my current solution: foreach i $List1 { set _break 0 foreach j $List2 { if [some condition] {incr _break; break } eval {blah blah blah} } if { $_break > 0 } { continue } } Conclusion: if you come from [PHP], now you know that there is no continue/break "loop depth argument". But several workarounds are offered above (and below?). [LV] Given that there's already the weird return arguments, what is the argument against enhancing continue as described above? Is there a technical issue with the proposal? [RHS] The idea of enhancing break and continue to accept an optional ''depth'' argument has been brought up multiple times in the past. I've never seen a counter-argument as to why it would be a bad idea... I've never seen anyone with enough motivation to even writeup a TIP for it either, though. I've had cases where I'd like to have had the feature, and I'm too lazy to writeup a TIP for it, so I can't really complain that someone else hasn't either. ''[escargo] 20 Apr 2005'' - In [Icon] '''break''' and '''next''' (the equivalent of continue) both have optional expressions that are evaluated in the context outside the current loop. So, if you are in inner loop and you want to leave that one loop, you use '''break'''. If you want to leave both an inner and outer loop, you would use '''break break'''. ---- [[ [Tcl syntax help] | [Arts and crafts of Tcl-Tk programming] | [Category Command] | [Category Control Structure] ]]