Submitted by Dacadey t3_z89cro in explainlikeimfive
xzt123 t1_iybn96i wrote
Reply to comment by Milnoc in ELI5: why is using "goto" considered to be a bad practice in programming? by Dacadey
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?
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.
xzt123 t1_iybr5of wrote
There's appropriate uses of goto, in C/C++ with nested loops and performance matters, sounds like a reasonable use.
Viewing a single comment thread. View all comments