1 of 55

1

2 of 55

Applying Cognitive Load Theory to Help Teach Iterative Loops in Code

On separate sticky-notes, record 4-6 examples of things that happen repetitively in your life.

Do Now:

https://bit.ly/loopypltw

2

3 of 55

On separate sticky-notes, record 4-6 examples of things that happen repetitively in your life.

Do Now:

Eating Granola: Scoop, Mouth, Chew, Swallow, Scoop, Mouth, Chew, Swallow…

(Game) Pinball Machine: 3 Balls then game ends.

School Bells Ring

(Music): Song B-I-N-G-O

(App Dev) Code -> Test -> Code -> Test -> Code -> Test…

School Bus Picking Up Students

3

4 of 55

David Czechowski (✅🏠🔑)

CSE/CSP PLTW Master Teacher

F.D.Roosevelt High School

New York's Beautiful Hudson Valley

High School of ~1,400 students, in a former-suburban district

davidczechowski@hpcsd.org

https://bit.ly/loopypltw

4

5 of 55

Overview

Look-Into Loops

2 ½ Types

Blocks/Python/Java

Introduction

Loops throughout the CS Curriculum

Novice Struggles

Cognitive Load

The Theory

Loop Schema

In-Practice

Classroom

Code

5

6 of 55

What are the 2 general uses of loops in code?

How does schema development improve cognitive ability?

How can loops in code be "chunked"?

6

7 of 55

Introduction

Loops are foundational & pervasive.

Loops are challenging.

7

8 of 55

Loops Throughout�Computer Science

Every structured programming language will have these 3 abilities:

Sequence - Execute one command, and then another…

Selection - Executing one of two commands based on a conditional value…

Repetition - Repeatedly executing commands based on a conditional value…

(Böhm–Jacopini Structured Program Theorem, 1966)

Introduction

8

9 of 55

Loops Throughout

the PLTW Courses

Gateway App Creators

  • 4 of 14 APBs in App Creators

Computer Science Essentials (CSE)

  • 23 of 32 APBs in CSE
  • CSE Loops

Computer Science Principles (CSP)

  • 21 of 48 APBs in CSP
  • CSP Loops

AP Computer Science 'A' (CSA)

  • __ of __ APBs in CSA

Introduction

9

10 of 55

The Loop Speed Bump

Introduction

10

11 of 55

Novice Struggles with Loops

  1. Assume that each action with the loop is repeated individually rather than as a unit.

Introduction

count = 0

while count < 5:

print(count)

count = count + 1

print("Done")

11

12 of 55

Novice Struggles with Loops

  • Assume that the loop condition (while) is constantly checked, rather than at the beginning of each iteration.

Introduction

while response != answer:

print("Guess #", guesses)

response = input()

guesses = guesses + 1

print("You got it")

12

13 of 55

Novice Struggles with Loops

  • Confusing the various constructs (for, for-each, etc) with implicit incrementing.

Introduction

for count in range(10):

print(count)

print("Done")

count = 0

while count < 10:

print(count)

count = count + 1

print("Done")

13

14 of 55

Novice Struggles with Loops

  • Why is it even called 'Loop'?

Introduction

14

15 of 55

Novice Struggles with Loops

  • Poor "Inside" the loop vs "Outside" the loop examples:
    • What happens repetitively?
    • What happens once?

Introduction

15

16 of 55

Novice Struggles with Loops

  • Due to computer speed, assuming that a loop happens instantaneously.

Introduction

16

17 of 55

Look-Into Loops

Deepen our CS knowledge and see how that might change classroom instruction.

17

18 of 55

Two Types of Loops

#1 Repeat Until/While a Condition

  • All we know is what causes the repetitions to end.
  • Example: Alarm clock beeps until a button is pressed.

#2 Fixed Number of Repetitions

  • As the repeating begin, we know how many times the repetition will occur.
  • Example: Singing B-I-N-G-O

Look-Into Loops

18

19 of 55

Two and a Half Types of Loops

#1 Repeat Until a Condition

  • All we know is what causes the repetitions to end.
  • Example: Alarm clock beeps until a button is pressed.

#2 Fixed Number of Repetitions

  • As the repeating begin, we know how many times the repetition will occur.
  • Example: Singing B-I-N-G-O

#2½ Once per item in a list. (Special Case of #2)

  • The number of repetitions is dictated by a list of items.
  • Example: Bus Driver repeatedly picks students up once for every name on the list.

Look-Into Loops

19

20 of 55

Which Types of Loop are your examples?

Look-Into Loops

Eating Granola: Scoop, Mouth, Chew, Swallow, Scoop, Mouth, Chew, Swallow…

(Game) Pinball Machine: 3 Balls then game ends.

School Bells Ring

(Music): Song B-I-N-G-O

(App Dev) Code -> Test -> Code -> Test -> Code -> Test…

School Bus Picking Up Students

20

21 of 55

Fixed Number of Repeats

Conditionally Repeat

Look-Into Loops

21

22 of 55

Fixed Number of Repeats

Conditionally Repeat

Look-Into Loops

Eating Granola: Scoop, Mouth, Chew, Swallow, Scoop, Mouth, Chew, Swallow…

(Game) Pinball Machine: 3 Balls then game ends.

School Bells Ring

(Music): Song B-I-N-G-O

(App Dev) Code -> Test -> Code -> Test -> Code -> Test…

School Bus Picking Up Students

(Repeat Once Per Item)

22

23 of 55

Your Loop Examples

Share your best example of each type with the person next to you.

Did you have examples for both types?

Look-Into Loops

23

24 of 55

Fixed Number of Repeats

Conditionally Repeat

Look-Into Loops

24

25 of 55

Fixed Number of Repeats

Conditionally Repeat

Look-Into Loops

25

26 of 55

Fixed Number of Repeats

Conditionally Repeat

Look-Into Loops

for i in range( __ ):

#

#

while _______:

#

#

26

27 of 55

Fixed Number of Repeats

Conditionally Repeat

Look-Into Loops

for(int i=0; i<__; i++)

{

// ...

}

while( ______ )

{

// ...

}

27

28 of 55

Other Loops

Look-Into Loops

for( Object o : objects )

{

// ...

}

28

29 of 55

Disadvantage of Other Loops (for novices)

Confusing the various constructs (for, for-each, etc) with implicit incrementing.

for count in range(10):

print(count)

print("Done")

count = 0

while count < 10:

print(count)

count = count + 1

print("Done")

Look-Into Loops

29

30 of 55

Cognitive Load

Assessing the mental demands for completing a task.

30

31 of 55

Cognitive Load Theory

Long-Term Memory

  • Possibly unlimited
  • "Memories" / "Knowledge"
  • Organized by collections of related information

Short-Term Working Memory

  • Extremely limited – three to nine “information elements”
  • "Schema" only count as a single element

Cognitive Load

31

32 of 55

Cognitive Load Demo

Demonstration

Cognitive Load

32

33 of 55

Cognitive Load on Learning

Extrinsic Load

  • Cognitive burden not related to the learning

Intrinsic Load

  • Complexity of the concept

Schema

  • Structured collections of prior learning recalled from long-term memory

Cognitive Load

33

34 of 55

Cognitive Load in Chess

In 5 seconds, a novice player could memorize the placement of only 4 pieces on a chess board, while a Chess Master could memorize 16 pieces.

(1973 "Perception in chess.")

Cognitive Load

34

35 of 55

Schema in Chess

The Chess Master wasn't seeing individual pieces, but rather recognizing common patterns… chunks!

(1973 "Perception in chess.")

Cognitive Load

35

36 of 55

Schema Demo

Demonstration

Cognitive Load

36

37 of 55

Cognitive Load of Loops

It is easy to say: "Jump 3 times" but it can require 5 or more blocks/lines of code to implement.

High Cognitive Load!

Cognitive Load

for(int i=0; i<10; i++)

{

jump();

}

37

38 of 55

A "Schema" for Loops

Help students establish a schema for loops.

Show them the 'patterns' in the code.

Reduce the intrinsic cognitive load.

Cognitive Load

38

39 of 55

An App Inventor Loop Schema

Cognitive Load

39

40 of 55

A VEXcode Loop Schema

Cognitive Load

40

41 of 55

A Python Loop Schema

Cognitive Load

count = 0

while count < :

#

#

#

#

count = count + 1

41

42 of 55

A Java Loop Schema

Cognitive Load

int count = 0;

while(count < )

{

count = count + 1;

}

42

43 of 55

General Loop Schema

While loop is in nearly every imperative programming language.

It looks very similar in most programming languages.

Can be used in both applications of a loop in code.

Cognitive Load

43

44 of 55

Known Number of Repeats

Repeat While Condition

Cognitive Load

44

45 of 55

In Practice

45

46 of 55

Careful around Loops

You are an 'expert'.

Tread lightly around loops with novices, it is cognitively dense.

Show students the pattern.

Teach students the pattern.

Require students to find the pattern.

In Practice

46

47 of 55

Example: CSE Activity 1.1.5

Sample Code for generating a random number of a specified length.

In Practice

47

48 of 55

Example: CSE Activity 1.1.5

See it with a schema…

In Practice

Repeating this many times:

48

49 of 55

The Loop Schema in Class

Poster

Website

Modeling

Externalizing It

In Practice

49

50 of 55

The Loop Schema in Class

Poster

Website

Modeling

Externalizing It

In Practice

50

51 of 55

The Loop Schema in Class

Poster

Website

Modeling

Externalizing It

In Practice

51

52 of 55

The Loop Schema in Class

Poster

Website

Modeling

Externalizing It

In Practice

"Ok, we need a loop. Let's put together the "oop chunk…"

52

53 of 55

Put it into Practice

What are you teaching next? (Or choose an Activity from one of the CS courses.)

Which "type" of loop is it?

How can you help students develop a loop "schema" to support their success?

In Practice

53

54 of 55

What are the 2 general uses of loops in code?

How does schema development improve cognitive ability?

How can loops in code be "chunked"?

54

55 of 55

Thank You!

Questions?

55