Double break out of a loop

N

Noodle

Hi, I have a real easy question for you experts ;)

I want to break out of two loops...is there a way of doing this without
using flags?

eg.

while(true){
while(true){
break; break;
}
}


Thanks for your help.
 
K

Knute Johnson

Noodle said:
Hi, I have a real easy question for you experts ;)

I want to break out of two loops...is there a way of doing this without
using flags?

eg.

while(true){
while(true){
break; break;
}
}


Thanks for your help.

done: while (true) {
while (true) {
break done;
}
}
 
L

Lasse Reichstein Nielsen

Noodle said:
Hi, I have a real easy question for you experts ;)

I want to break out of two loops...is there a way of doing this without
using flags?

labelOfOuterLoop: while(true) {
while(true) {
break labelOfOuterLoop;
}
}

The default of "break" is to end the nearest syntactically enclosing
loop. If you want to break any other enclosing statement, you have to
point out which block to break. That is done by giving the statement a
name, using a statement label, and using that name in the break.

/L
 
N

Noodle

Lasse said:
labelOfOuterLoop: while(true) {
while(true) {
break labelOfOuterLoop;
}
}

The default of "break" is to end the nearest syntactically enclosing
loop. If you want to break any other enclosing statement, you have to
point out which block to break. That is done by giving the statement a
name, using a statement label, and using that name in the break.

/L


Thankyou for your responses Knute and Lasse. Thats exactly what I
wanted.

Noodle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top