What are the advantages of goto in iterations/functions?

Asked 1 years ago, Updated 1 years ago, 128 views

At school, I was taught not to use Goto under any circumstances Looking at libavcodec, surprisingly, there are still many people who use goto.

What are the advantages of goto in iterations/functions? You're telling me not to use it, but do I keep using it?

c exception-handling language-agnostic goto

2022-09-22 22:19

1 Answers

Functions with dynamic assignments must free the assigned portion without ending immediately when leaving the function.

Usually, free at the end, so if you label it and write goto statement, You can process the memory release part in batches

Also, if goto is useful, It's time for code to stop all repeat statements if the conditions in the innermost repeat statements are not met in the nested repeat statements.

If you don't write goto, you have to set a flag and make a code to check the flag for each conditional statement. goto can be solved at once, which reduces the length of the code by a lot and makes it easier to understand

There are many other advantages, but I don't think I can make it less. People say that it's better not to use Goto break, exit, and continue all contain goto when opened We have to say that we are already writing goto in a different form.


2022-09-22 22:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.