break

  • Thread starter Colin JN Breame
  • Start date
C

Colin JN Breame

Is there an equivalent C++ construct to Java's:

outer:
while (true) {
while (cond1) {
if (cond2) {
break outer;
}
}
}

Thanks
 
R

Russell Hanneken

Colin said:
Is there an equivalent C++ construct to Java's:

outer:
while (true) {
while (cond1) {
if (cond2) {
break outer;
}
}
}

Well, there's goto:

while (1) {
while (cond1) {
if (cond2) {
goto AFTER_LOOP;
}
}
}
AFTER_LOOP:
// Goto takes us here.

Of course, one should be careful about using goto. See the FAQ:

http://www.eskimo.com/~scs/C-faq/q17.10.html

Some would say the case against goto applies equally to break (except in
switch blocks) and continue.
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top