Home  >  Article  >  What are the three most basic program control structures?

What are the three most basic program control structures?

青灯夜游
青灯夜游Original
2020-08-21 14:06:4326308browse

The most basic program control structures include sequence, selection, and loop. Theory and practice have proven that no matter how complex the algorithm is, it can be constructed through three basic control structures: sequence, selection, and loop; each structure has only one entrance and exit; a multi-layer nested program composed of these three basic structures is called is a structured program.

What are the three most basic program control structures?

#A program is a sequence of statements, and executing a program means executing the statements in the program in a specific order. The transition of execution points in the program is called the control flow. When a certain statement in the program is executed, it is also said that control is transferred to that statement. Since solutions to complex problems may involve complex execution sequences, programming languages ​​must provide means to express complex control flows, called control structures of the programming language, or program control structures.

Program control structure refers to a series of actions executed in a certain order to solve a certain problem.

Theory and practice have proven that no matter how complex the algorithm is, it can be constructed through three basic control structures: sequence, selection, and loop. Each structure has only one entrance and exit. A multi-level nested program composed of these three basic structures is called a structured program.

  • Sequential structure programming is the simplest. Just write the corresponding statements in the order of solving the problem. Its execution order is from top to bottom, one after another.

  • The selection structure is used to judge given conditions, judge certain conditions based on the results of the judgment, and control the flow of the program based on the results of the judgment.

  • The loop structure can reduce the workload of repeated writing of the source program and is used to describe the problem of repeatedly executing a certain algorithm. This is the program structure that best utilizes the computer's expertise in programming. The loop structure can be seen as a combination of a conditional statement and a turnaround statement.

Sequential structure:

The sequential structure is to execute sentence after sentence from beginning to end until the last sentence is executed. As shown below

What are the three most basic program control structures?

Select structure

After reaching a certain node, it will decide which one to go to next based on the result of a judgment. Branch direction execution. As shown in the figure below

What are the three most basic program control structures?

Loop structure

The loop structure has a loop body, and the loop body is a piece of code. For loop structures, the key is to decide how many times to execute the loop body based on the judgment result;

What are the three most basic program control structures?

For more related knowledge, please visit:PHP Chinese website !

The above is the detailed content of What are the three most basic program control structures?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What are the cast rules?Next article:What are the cast rules?