View page as slide show

Structured Programming Concepts

Mithat Konar
July 21, 2018

Topics

What is it?

Why is it important?

Theoretical reasons

Practical reasons

Core concepts

Control flow

Scenario

First try

Ash gets a cup of food every day.
Her water needs to be filled if it's running low.
She also needs to play fetch with her favorite toy.

Sequence

“Ash gets a cup of food every day.”

open the bag of catfood on the counter
scoop out one cup of food
put the scoop of food into her food dish
reseal the bag of catfood

Selection

“Her water needs to be filled if it's running low.”

if the water level in the water dish is low
    fill a glass of water from the filtered water pitcher on the counter
    pour the glass of water into the water dish

Repetition

“She also needs to play fetch with her favorite toy.”

toss  Ash's favorite toy
while Ash brings it back
    pat her on the head
    toss Ash's favorite toy

Code Examples

Sequence

a = 5
b = 4
c = a * b
print("The value of c is", c)

Selection

if a > 60:
    print("Your score is", a)
    print("You passed the course!")    

Repetition

n = 1
while n < 10:
    print(n)
    k = n + 1
    n = k

<html> <script> var uls = document.getElementsByTagName('ul'); for(var i=0,j=uls.length;i<j;++i){uls[i].setAttribute('class','incremental')} </script> </html>