Python control structures
According to the structure theorem, any computer program can be written using the basic control structures . A control structure (or flow of control) is a block of programming that analyses variables and chooses a direction in which to go based on given parameters. In simple sentence, a control structure is just a decision that the computer makes. So, it is the basic decision-making process in programming and flow of control determines how a computer program will respond when given certain conditions and parameters. There are two basic aspects of computer programming: data and instructions . To work with data, you need to understand variables and data types; to work with instructions, you need to understand control structures and statements. Flow of control through any given program is implemented with three basic types of control structures: Sequential, Selection and Repetition.
Sequential
Sequential execution is when statements are executed one after another in order. You don't need to do anything more for this to happen.
Selection
Selection used for decisions, branching - choosing between 2 or more alternative paths.
- if
- if...else
- switch
Repetition
Repetition used for looping, i.e. repeating a piece of code multiple times in a row.
- while loop
- do..while loop
- for loop
Related Topics