I wondered, why do we need other operators and cycles if there is a powerful GoTo keyword?

GoTo can be replaced by any cycle, as well as GoTo gives space for creativity, as you can call tags so that it will pick up the head.

Also, all the same, of course, the beautiful code turns into a GoTO sequence in machine language.

In my opinion, GoTo is something like Bazon Higgs, which is considered to be a part of God, and GoTo is an operator of a machine god.

  • 2
    A piece of god ... But in fact, only jmp . One of the many instructions. Even in machine code, loops are organized without goto; - vp_arth
  • 2
    "Why do we need programming languages ​​when there is an assembler?" ... "Why do you need an assembler when there is a machine code?" - andreymal
  • 2
    Think smart, envy! However, even greater prospects are opening up if we use the Russian analog instead of GoTo (we have everything in Russian here), while taking into account the richness of the language, the original is broken down into at least 3 - IdiTy operator, IdiNa operator, and the superoperator - IdiSka :-) to exit other operators :-) - Eugene Bartosh
  • 2
    goto is a degenerate form of a conditional transition. Therefore, it is not about zones (although it can also be zones). - KoVadim
  • 2
    @vp_arth is actually also jnz , jz , je , jge ... there are a lot of them, according to the flags used and positivity / negativity. - D-side

3 answers 3

The problem is that the code is written not for the compiler, but for the person. For your colleagues and for you in half a year.

The insane power of the goto operator turns its weak expressiveness . With goto you can express exactly that everything : iterating through the list, checking the logical condition, and calling the subroutine, whatever. Seeing the goto , you have to restore the logic each time to understand the text. And this is a waste of time and mental effort that you have to apply every time you need to understand whether the code is correct, or, even worse, find the error and correct it.

So there are other operators in the languages ​​for people reading and trying to understand the logic of the program. But the computer doesn't care, he would work with one goto , the piece of iron is dull.

    This is just one of the 3rd generation programming language styles. In my opinion , it appeared rather for learning new thinking than for real gain.

    Second-generation languages ​​(Assemblers) without GoTO (JMP) simply could not work. Transitional languages ​​(Basic, Fortran) also numbered lines and used transitions.

    The style "without goto" is just a style, nothing more. Sometimes algorithms with goto work faster, because take full advantage of the processor itself

    • The operator of God ... There is something in it. It was the idea of ​​an abstract universal algorithmic machine of Emil Post that contained something like goto. Only 6 operations, allowing to implement any algorithm ... This is one of them
    • The climax: URISC (computer with one instruction). - D-side
    1. Not all languages ​​have this statement.
    2. Thoughtless use lead to a code that is very difficult to understand and maintain (spaghetti code).
    3. This operator does not express the intentions of the programmer.
    • one
      mindless application of any operator / technology always leads to code that is difficult to understand :). And the goto programmer’s intent is very accurate. Some use it right and left every day. - KoVadim
    • it does not express intentions, but expresses their absence :) - Mikhail Vaysman
    • one
      If only it were possible to write goto and the compiler inserted the transition to any place - then it would be a lack of intention. Moreover, anywhere they can not go. - KoVadim
    • what is the best intent - if + goto or while? - Mikhail Vaysman
    • 2
      both. It all depends on the task. Some simulate while through if + goto, and some use the idiom do { break; } while(0); do { break; } while(0); , so as not to write goto (but their code can be rewritten without using either one or the other). - KoVadim