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 execution is when statements are executed one after another in order. You don't need to do anything more for this to happen.
Selection used for decisions, branching - choosing between 2 or more alternative paths.
Repetition used for looping, i.e. repeating a piece of code multiple times in a row.
- while loop
- do..while loop
- for loop
These control structures can be combined in computer programming. A sequence may contain several loops; a loop may contain a loop nested within it, or the two branches of a conditional may each contain sequences with loops and more conditionals. From the following lessons you can understand the control structures and statements in Python language.