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.
Python control structures

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.

  1. if
  2. if...else
  3. switch

Repetition

Repetition used for looping, i.e. repeating a piece of code multiple times in a row.

  1. while loop
  2. do..while loop
  3. 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.