Date: Tue, 10 Mar 2020 20:26:19 -0700
I think you'd make a much more compelling case if this were a real
scenario, rather than merely a pseudo-random integer loop with
names like "x", "y", "z", "label1" and "label2". As it stands, the labels
don't provide any added value to this code.
With current C++, I'd have to write it this way:
int main() {
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 5; y++) {
for (int z = 0; z < 5; z++) {
std::cout << x << ',' << y << ',' << z << std::endl;
if (z + y == 8) goto continue_y_loop;
if (z + x == 3) goto break_y_loop;
if (x + y + z == 13) goto break_x_loop;
}
continue_y_loop:;
}
break_y_loop:;
}
break_x_loop:;
}
To be honest, that doesn't seem so bad.
= - = - = - =
May I ask: what scenario made you want to ask for this feature? Perhaps if
you show what you were really trying to do, it could be more compelling?
-- Jorg
On Tue, Mar 10, 2020 at 5:12 PM Ryan Nicholl via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>
> I'd like to suggest adopting labeled break and continue statements,
>
> e.g.
>
> label1: for( int x = 0; x < 5; x++)
> {
> label2: for (int y = 0; y < 5; y++)
> {
> for (int z = 0; z < 5; z++)
> {
> std::cout << x << ',' << y << ',' << z << std::endl;
> if (z+y == 8) continue label2;
> if (z+x == 3) break label2;
> if (x + y + z == 13) break label1;
> }
> }
> }
>
> Other languages have it, and it's convenient with nested loops.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
scenario, rather than merely a pseudo-random integer loop with
names like "x", "y", "z", "label1" and "label2". As it stands, the labels
don't provide any added value to this code.
With current C++, I'd have to write it this way:
int main() {
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 5; y++) {
for (int z = 0; z < 5; z++) {
std::cout << x << ',' << y << ',' << z << std::endl;
if (z + y == 8) goto continue_y_loop;
if (z + x == 3) goto break_y_loop;
if (x + y + z == 13) goto break_x_loop;
}
continue_y_loop:;
}
break_y_loop:;
}
break_x_loop:;
}
To be honest, that doesn't seem so bad.
= - = - = - =
May I ask: what scenario made you want to ask for this feature? Perhaps if
you show what you were really trying to do, it could be more compelling?
-- Jorg
On Tue, Mar 10, 2020 at 5:12 PM Ryan Nicholl via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>
> I'd like to suggest adopting labeled break and continue statements,
>
> e.g.
>
> label1: for( int x = 0; x < 5; x++)
> {
> label2: for (int y = 0; y < 5; y++)
> {
> for (int z = 0; z < 5; z++)
> {
> std::cout << x << ',' << y << ',' << z << std::endl;
> if (z+y == 8) continue label2;
> if (z+x == 3) break label2;
> if (x + y + z == 13) break label1;
> }
> }
> }
>
> Other languages have it, and it's convenient with nested loops.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2020-03-10 22:29:18