Traditional Culture Encyclopedia - Traditional stories - How to do the program flow?

How to do the program flow?

A program flow chart is a chart that describes all the operations or judgments needed in a special program with specified symbols. This flow chart focuses on the logic and processing sequence of the program, and specifically describes the logic and steps of solving problems by microcomputer. When there are many loop statements and transfer statements in the program, the structure of the program will be more complicated, which will bring difficulties to the design and reading of the program. The program flow chart draws the program flow direction in the form of graphics, which is a graphical representation of the algorithm and has the characteristics of intuition, clarity and easier understanding. [2]

The program flow chart consists of processing box, judgment box, start-stop box, connection point, flow line and comment box. Combined with the corresponding algorithm, the whole program flow chart is formed.

The processing framework has processing function; The judgment box (diamond box) has the function of conditional judgment, with one entrance and two exits; The start-stop box indicates the start or end of the program; The connection point can connect the process line; Process line (indicating the path and direction of the process; The comment box is used to make necessary supplementary explanations for the operations of some boxes in the flowchart. [3]

Three basic structures of program flow chart

Any complex algorithm can be composed of three basic structures: sequence structure, selection (branching) structure and cyclic structure. Therefore, when constructing the algorithm, only these three basic structures are regarded as "building units" and the specifications of the three basic structures are observed. Basic structures can be juxtaposed and mutually inclusive, but they are not allowed to cross and directly transfer from one structure to another. Because the whole algorithm is composed of three basic structures, just like building with modules, the structure is clear, and it is easy to verify the correctness and correct mistakes. This method is a structured method. The programming that follows this method is structured programming. Therefore, as long as the drawing methods of three basic structures are specified, the flowchart of any algorithm can be drawn. [4]

(1) sequence structure

Sequence structure is a simple linear structure, and blocks are executed in sequence. The basic form of the flow chart is shown in the figure, and the execution order of the statements is: ABC. [ 1]

(2) Select (Branch) Structure

This structure is to judge a given condition and execute the contents of different boxes when the condition is true or false. There are two basic shapes. [ 1]

(3) circular structure

There are two basic forms of loop structure: while loop and do-while loop. A. while loop: its execution order is: when the condition is true, repeat a; Once the condition is false, jump out of the loop and execute the statement immediately after the loop. B. do-while loop: the execution order is: execute a first, and then judge the condition. When the condition is true, it is always executed in a loop. Once the condition is false, the loop is ended and the next statement is executed immediately after the loop.