Sat. Jan 21st, 2023

Procedural Programming – Control Structures

A control structure is anything that determines the order in which statements are executed.

In the procedural programming paradigm, control structures are:

  • Sequence
  • Conditional
  • Iterative

Sequence

In the absence of any other instruction, statements are executed in sequence: in the order in which they are written.

You can control the order in which statements are executed, simply be arranging them in the desired order.

C#
Console.WriteLine("Hello my name is");
Console.WriteLine("Chris");

Python
print("Hello my name is")
print("Chris")

Because these instructions are executed in sequence, you would expect the output to be “Hello my name is Chris”, and not “Chris Hello my name is”.

Conditional

As discussed here, conditional statements allow code to be far more flexible, by allowing conditions to be evaluated to determine whether or not blocks of code should be executed. Clearly, this is another method of controlling the order in which code is executed.

Iterative

The final method of controlling the flow of execution is through iterative statements. These are loops – commands such as while, or for. Clearly, if you are instructing a block of code to repeat ten times, you are controlling the flow of execution.