About goto statement

zhaozj2021-02-17  55

In the late 1960s and 1970s, the debate about goto statement was more fierce.

The person who advocates removing the GOTO statement from the advanced language believes: GOTO statement is a harmful statement that affects the program structure; their main reason is that the goto statement makes the program's static structure and the dynamic execution of the program. Different, this makes the program difficult to read, it is difficult to check the error. For a program, people are most concerned about whether he runs correctly, after removing the GOTO statement, you can directly reflect the running process of the program directly from the program structure. In this way, not only make the program's structure clear, easy to read, easy to check, and also contribute to proof of program correctness.

Different comments believe that the GOTO statement is more flexible, and some situations can improve the efficiency of the program. If you emphasize the delete goto statement, some cases will make the program too complicated, add some unnecessary amounts.

In 1974, DekNuth (the author of the super big cow, the author of Computer Programming) made a comprehensive and fair review of the battle of GOTO statements, and his basic view is: not restricted use of GOTO statements, especially With the GOTO statement that is returned, it will make the structure of the program difficult to understand. This situation should try to avoid using a goto statement; in order to improve the efficiency of the program, it does not destroy the good structure of the program, and use some goto statement It is necessary. In his words: "Some situations, I advocate abolishing the steering statement, some cases, I advocate introducing the steering statement." (See d.e.knuth: "Structured programming with steering statements")

Further, can the GOTO statement be eliminated? Or do you say that the language ingredients will be canceled from the programming language? The answer is yes. In 1966, G.Jacopini and C.bohm proved in theory: Any procedure can be expressed in sequence structures, conditional structures, and cyclic structures. The method of specific Elimination of GOTO statements is: increasing auxiliary variables or changing program execution order. For details of this, you can refer to the information of the program design theory.

It should be noted that although the discussion of the structured programming is starting from the abolition goto statement, it must not be considered that the structural program is to avoid the programming method of the GOTO statement. In fact, structural programming discussing a new programming method and style. The focus of his concern is the structure of the program's structure, and there is no goto statement is not a logo. That is to say, restrictions and avoiding the GOTO statement is a means of obtaining a structured program, not our purpose.

Talk later about structured programming. The procedures for good structures are generally consisting of 7 structures: a sequence structure; three selection structures: 1.if-dam; 2.if-dam-else; branch selection: Pascal is "Case .. OF. .., "; c, c , Java is" Switch (..) Case ...: ... "; three cyclic structure: 1.While loop: first judgment the condition P, if you are constantly being executed Circulation body a; 2.Repeat cycle: first execute the cyclic body A, then determine the condition P, if the P is established, return to the entry to perform the cyclic body A; "Repeat..until .." in Pascal; in C, C , Java is "do {...} while (..); 3. N 1/2 loop: start A from the entrance, then determine the p, if the P is established, execute B, then return to Entrance execution a; if P is not settled, it reaches the exit; this cycle is in the general programming language is a characteristic of the seven structures of the For loop: each structure strictly abides by "an entrance, an export" principle. This principle is a very important principle in structured programming. It is also because of this principle, a complex program can be broken down into several structures and several layers, so that the structure of the program is clear and easy to understand.

Programs written in these seven structures can design the program with "self-top, gradually refine" programming methods. The method organizes people's thinking activities in accordance with the first overall situation, first, first abstract process, and make the programmed program structure, easy to read and modify. At the same time, the process of gradually refining the process of programming, that is, the method of taking edge design side verification, to simplify the verification of the program correctness.

转载请注明原文地址:https://www.9cbs.com/read-30830.html

New Post(0)