Control flow in procedural programming

Programming Paradigm Concepts

Eleanor Thomas

Senior Data Analytics Engineer

What is control flow?

  • Control flow: set of keywords and processes within a programming language that indicate how the logic of the code should be stepped through
  • Examples of control flow statements:
    • if/else statements
    • for loops and while loops
    • Function definition using def

Directing flow

Programming Paradigm Concepts

Combining elements of control flow (if statements and for loops)

if my_height > your_height:
    print("I'm taller!")
for height in height_list:
    print(height)

Combined:

for height in height_list:
    if my_height > height:
        print("I am taller than ", height)
Programming Paradigm Concepts

Combining elements of control flow in functions

def compare_heights(my_height, height_list):
    for height in height_list:
        if my_height > height:
            print("I am taller than ", height)
    return

my_height = 63 height_list = [62, 67, 70]
compare_heights(my_height, height_list)
Programming Paradigm Concepts

Control flow in procedural programming

  • Control flow statements make procedural programming possible in Python
  • Structure program logic in a step-by-step way with reusable chunks of logic
  • Code this logic in Python with if statements, loops, and Python functions
  • Control flow creates procedures which implement separation of responsibilities

Person typing

Programming Paradigm Concepts

Let's practice!

Programming Paradigm Concepts

Preparing Video For Download...