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.
Sequential execution is the process where statements are executed consecutively in a specified order. No additional action is required to facilitate this progression.
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 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.