T
T
Taras Serevann2014-06-29 19:51:03
Programming
Taras Serevann, 2014-06-29 19:51:03

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

7 answer(s)
I
iamnothing, 2014-06-29
@iamnothing

You better tell me in what situation you urgently need a goto?

M
Mikhail Doshevsky, 2014-06-30
@MikhailD

It is not some operator or technology in itself that considers bad form, but its incorrect or inappropriate use. Everything depends on your tasks.

A
Alexander N++, 2014-06-29
@sanchezzzhak

Function call();
return;
Write code in such a way that you don't have to use it.
Perfect code book to help)

L
lookid, 2014-06-29
@lookid

if ... : break;
function();
return

S
Sergey, 2014-06-29
Protko @Fesor

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.

V
Valentine, 2014-06-29
@vvpoloskin

Now in PL there are enough flow control functions:
1) conditional statements
2) loops
3) exceptions
4) function calls
All this is usually enough

P
Pavel Gogolinsky, 2014-07-01
@gogolinsky

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 question

Ask a Question

731 491 924 answers to any question