Answer the question
In order to leave comments, you need to log in
What to use instead of goto?
I've heard that goto is bad form, but if not goto, what should I use? What are the alternatives to goto?
Answer the question
In order to leave comments, you need to log in
It is not some operator or technology in itself that considers bad form, but its incorrect or inappropriate use. Everything depends on your tasks.
Function call();
return;
Write code in such a way that you don't have to use it.
Perfect code book to help)
Looking for what purposes. If you have a parser there, then goto can channel normally, finite automata ... everything where you need to quickly and conveniently change states. You can, of course, without goto, but it will not be as efficient in terms of performance.
In 95% of cases, goto, large nesting of conditions, heaps of ifelse, switch-cases, etc. will be bad manners. But still there are cases when it is impossible to do without it.
ps If you pay attention to the block "similar questions", there are a couple of useful links.
Now in PL there are enough flow control functions:
1) conditional statements
2) loops
3) exceptions
4) function calls
All this is usually enough
All right. goto is bad form. The fact is that using goto you can easily get confused where the code is currently being executed. For the same reason, it's also best not to use break if possible. Code should be written as if it were a story in plain language. "Action" should last from top to bottom, from beginning to end, without jumps and breaks. Therefore, before starting programming, it is worth considering such an algorithm that would involve only branches and loops.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question