Viewing a single comment thread. View all comments

Milnoc t1_iybikwv wrote

I use goto, but only sparingly. I use them to get out of complex nested loops or switch/cases and jump either to the end or to the beginning of a function where I would have a maintenance routine to clean up before leaving the function or to reinitialize and restart the nested loop.

If you start using gotos where they're not needed at all, you're just asking for trouble down the road.

0

xzt123 t1_iybn96i wrote

What language? In Java you can label the loop and break out of the loop by name.

In C#, your use of goto is probably ok. C# has more rules about goto, it can't be anywhere and I believe it can't skip variable definitions. C# also has a use of goto where switch blocks cannot fall through cases, that have statements, without an explicit goto statement to go to the next labeled case. It makes missing a break; statement accidentally not possible.

Anyway, obviously a ton of languages out there, so curious which one?

1

Milnoc t1_iybpcua wrote

C/C++. But as I've said, I use them very sparingly to kick the process out of a nested loop or switch block into a general maintenance chunk of code. I would never use it to jump around within a loop or switch block.

1

xzt123 t1_iybr5of wrote

There's appropriate uses of goto, in C/C++ with nested loops and performance matters, sounds like a reasonable use.

1