C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Continue down the ladder (if-else, catch)

From: David Brown <david.brown_at_[hidden]>
Date: Thu, 3 Jul 2025 20:52:46 +0200
You have found the answer yourself - "goto". Instead of adding a "goto
else" feature, write "goto else1" and change the next (or other
appropriate line) "else if" to "else else1: if". There's no need for a
change to the language - you can write code in your chosen
incomprehensible spaghetti style already.

>
> Sometimes in an "if else ladder", you want to enter one of the code
> blocks, but if something goes wrong in that code block, you want to
> jump back out of it and continue down the ladder. So maybe "goto
> else;" could be used for this? The above code could become:
>
> unsigned index = 7u;
> if ( 7u == p.size() ) // P1234R0
> {
> // fall through
> }
> else if ( isdigit(p[7]) ) // length is >= 8
> {
> rev *= 10u;
> rev += (p[7]-'0');
> if ( p.size() > 8u )
> {
> ++index;
> goto else;
> }
> // fall through
> }
> else if ( ('\0' == p[index]) || ('.' == p[index]) )
> // length >= 8u
> {
> // fall through
> }
> else // length >= 8u
> {
> break;
> }
>
> This would greatly simplify some of the most complicated "if else ladders".
>
> first catch handler, and then enters the second catch handler also.


If you think that simplifies your code, your real code must be truly
gruesome to behold.

David

Received on 2025-07-03 18:52:56