Python control structures

According to the structure theorem, any computer program can be composed using basic control structures. A control structure (or flow of control) is a programming construct that assesses variables and selects a path to follow based on provided parameters. In simpler terms, a control structure represents a decision that the computer executes. Thus, it forms the fundamental decision-making process in programming, where the flow of control dictates how a computer program responds under specific conditions and parameters.

There are two fundamental aspects of computer programming: data and instructions. To engage with data, it is necessary to comprehend variables and data types. To engage with instructions, an understanding of control structures and statements is required. The flow of control through any given program is achieved using three fundamental types of control structures: Sequential, Selection, and Repetition.


Python control structures

Sequential

Sequential execution is the process where statements are executed consecutively in a specified order. No additional action is required to facilitate this progression.

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

Conclusion

These control structures can be combined within computer programming. A sequence might encompass multiple loops; a loop could incorporate a nested loop, or both branches of a conditional might include sequences with loops and additional conditionals. The forthcoming lessons will provide you with an understanding of control structures and statements within the Python programming language.