Re: Suggested extention of the break statement
On Aug 23, 6:11 pm, Hyman Rosen <hyro...@mail.com> wrote:
The current single-level break and continue statements are
inadequate for many reasonable loop structures anyway. C++
should take a page from Ada and allow 'break label;' and
'continue label;' where label is attached to a statement.
(We would require that the label for a continue actually
label a loop, but any statement could have a break label.)
So,
t1: try {
stuff();
if (condition()) {
break t1;
}
} catch (...) {
handle();
}
This break looks like a no-op to me, but if you put code beyond the
break, you still have:
try {
stuff();
if (!condition()) {
more_stuff();
}
catch ...
f1: for (int i = 0; i < 100; ++i) {
for (int j = 0; j < i; ++j) {
if (no_good(j)) {
continue f1;
}
}
cout << i << " is good!" << endl;
}
bool is_good(i) {
for (int j = 0; j < i; ++j) {
if (no_good(j)) return false;
}
return true;
}
// What we really should be writing:
bool is_good(i) {
return std::find(0, i, lambda(j) { no_good(j) }) == i;
}
w1: while (cin >> ch) {
switch(ch) {
case 'Q': break w1;
case '+': do_add(); break;
default: sing(); break;
}
}
while (cin >> ch && process_or_quit(ch))
// process char in some thing.
// Returns true if quit char ('Q') read
bool process_or_quit(char) {
switch (ch) {
case 'Q': return false;
case '+': do_add(); break;
default: sing(); break;
}
return true;
}
i1: if (c1) {
x();
if (c2) {
break i1; //----
} // |
y(); // |
} else if (c3) { // |
z(); // |
} else { // |
w(); // |
} // |
// goes here <----------
if (c1) {
x;
if (!c2) y();
} else if (c3) {
z();
} else {
w();
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]