Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Abort the loop

Status
Not open for further replies.

snowingnow

Programmer
Jun 1, 2006
32
0
0
CA
I have nested loop, how can i terminate the loop if i find the seaching thing
such as
foreach a listvalue1 {
foreach b listvalue2 {
if {$b=$a}{
set c "something"
i want to abort to outnner most
}
else {
keep doing both loop}
...
how can i do that?
thanks
 
I think you can only abort from the inside out, using the break commmand:
break


DESCRIPTION
This command is typically invoked inside the body of a looping command such as for or foreach or while. It returns a TCL_BREAK code, which causes a break exception to occur. The exception causes the current script to be aborted out to the innermost containing loop command, which then aborts its execution and returns normally. Break exceptions are also handled in a few other situations, such as the catch command, Tk event bindings, and the outermost scripts of procedure bodies.

I suggest you break at the inner loop, and test for $a=$b in the outer loop, too, and break there if the condition is right.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top