Structured programming notes
2. Control Structures
Control structures are fundamental programming constructs that determine the order in which statements are executed in a program. Instead of executing statements strictly from top to bottom, control structures allow a program to make decisions, repeat actions, and control the flow of execution based on conditions.
They are essential in structured programming because they help break complex problems into logical, manageable blocks, making programs easier to understand, test, and maintain.
Types of Control Structures
-
Sequential Control Structure
-
Statements are executed one after another in the order they appear.
-
This is the simplest form of control flow and is used when no decision or repetition is required.
-
-
Selection (Decision-Making) Control Structure
-
Allows the program to choose between different paths of execution based on a condition.
-
Common statements include
if,if–else, andswitch. -
Used when different actions are needed for different conditions.
-
-
Iteration (Looping) Control Structure
-
Enables a set of statements to be executed repeatedly as long as a condition is true or until a condition is met.
-
Common loops include
while,do–while, andfor. -
Used when tasks need to be repeated, such as processing data collections.
-
Importance of Control Structures
-
Improve program clarity and readability
-
Reduce complexity in program logic
-
Support structured and modular programming
-
Help avoid unstructured jumps like excessive use of
goto