-
The goto statement is a transfer instruction, which directly changes the current instruction pointer IP of the CPU to the instruction address pointed to by the goto statement, and then continues to execute from this address. From the assembly language point of view, the goto statement corresponds to the assembly language JMP instructions, but the danger of assembly language is that the jump of JMP instructions is unconstrained or less constrained, and the machine instruction level can be jumped at will, unless the instructions are strictly checked before execution, which is actually very difficult.
Early algorithm languages, such as Fortran, Pascal, Basic, etc., all supported goto statements, because there were fewer statements at that time, and the branch structure and loop structure needed to be implemented with the help of goto statements. However, these high-level languages impose strict restrictions on goto statements, such as: (1) they can jump from inside to outside of a structure (conditionals, loops), and vice versa; (2) It is not allowed to jump out of the subprogram directly, but to use a return statement similar to return to exit the subprogram, of course, jumping from the main program into the subprogram is absolutely prohibited; Wait a minute.
These limitations still work for modern algorithmic languages that also support goto statements.
With the structuring and modularization of languages, some high-level languages no longer support goto statements. This is done for the purpose of making the program easy to read and understand, and to facilitate the maintenance of the program. However, there are always two sides to things, and the efficiency of the execution of the program is slightly reduced by structuring and modularization.
For example, after programming the Eight Queens, you will know that when a structure has multiple exits to directly "short-circuit" jumps, the efficiency is higher, and if it is judged by state variables and then through conditional statements, it will definitely reduce efficiency. I think this is one of the reasons why some algorithmic languages still retain goto statements.
Just like atomic energy, it can benefit humanity as well as cause serious harm to it. The goto statement also has its two sides, and it is not used in the programming as much as possible, and it is used carefully in the pursuit of efficiency.
-
The current programming languages all use structured languages, and the use of goto statements is generally not advocated in structured program design
1. It is more flexible to use goto statements when the program is relatively simple, but it is easy to cause confusion in the program process when the program is more complex.
2. Writing a program with a goto statement is difficult for people who look at the program later.
3. The process of debugging the program can also become difficult.
-
The goto statement is an unconditional transfer statement, and its general format is as follows: goto statement number; The statement mark is a symbol written according to the identifier specification, placed in front of a sentence line, and a colon is added after the mark. Statement labels serve as identification statements and are used in conjunction with goto statements.
The C language does not limit the number of times a designator can be used in the tremor program, but each designator must not be the same. The semantics of the goto statement is to change the direction of the program flow to execute the statement identified by the statement marker.
Goto statements are often used in conjunction with conditional statements. It can be used to realize the transfer of conditions, form a loop, and jump out of the loop.
In structured program design, it is generally not advisable to use goto statements, so as not to cause confusion in the program flow and make it difficult to understand and debug the program.
rem sets the date format to yyyymmdd
if %date%==20080806 goto doitrem If the time is equal to 20080806 jump to the designator doitrem If the time is not equal to, proceed to the next step. >>>More
Summary: Both. With the noun to is a preposition, which can be seen as a prepositional phrase as a way adverbial. >>>More
The difference between go to and go is: different meanings, different usages, and different emphasis. >>>More
Evaluate other people's performance in English, so to speak: >>>More
1 > remember what should be remembered and forget what should be forgotten. Change what can be changed, accept what can't be changed. >>>More