Beeflang - open source performance-oriented compiled programming language
Sebastiaan Koppe
mail at skoppe.eu
Fri Jan 10 09:33:01 UTC 2020
On Friday, 10 January 2020 at 09:00:53 UTC, Patrick Schluter
wrote:
> On Thursday, 9 January 2020 at 17:41:31 UTC, jmh530 wrote:
>> void main() {
>> int result;
>> do {
>> int c = 2;
>> if (c == 0)
>> break;
>> string op = "+";
>> if (op != "+")
>> break;
>> int c2 = 3;
>> if (c2 == 0)
>> break;
>> result = c + c2;
>> } while (false);
>> assert(result == 5);
>> }
>
> Use goto, then people will know that these breaks are gotos in
> disguise and the code is more readable (less indentation, no
> confusion with a loop, no catastrophic nesting where you don't
> know where the break go to) and is much simpler to modify.
>
> void main() {
> int result;
> int c = 2;
> if (c == 0)
> goto skip;
> string op = "+";
> if (op != "+")
> goto skip;
> int c2 = 3;
> if (c2 == 0)
> goto skip;
> result = c + c2;
> skip:
> assert(result == 5);
> }
>
or don't do too many things at-once:
void main() {
auto result() {
int c = 2;
if (c == 0)
return c;
string op = "+";
if (op != "+")
return c;
int c2 = 3;
if (c2 == 0)
return c;
return c + c2;
}
assert(result == 5);
}
More information about the Digitalmars-d
mailing list