1
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
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
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
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
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
Introduction
Loops are foundational & pervasive.
Loops are challenging.
7
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
Loops Throughout
the PLTW Courses
Gateway App Creators
Computer Science Essentials (CSE)
Computer Science Principles (CSP)
AP Computer Science 'A' (CSA)
Introduction
9
The Loop Speed Bump
Introduction
10
Novice Struggles with Loops
Introduction
count = 0
while count < 5:
print(count)
count = count + 1
print("Done")
11
Novice Struggles with Loops
Introduction
while response != answer:
print("Guess #", guesses)
response = input()
guesses = guesses + 1
print("You got it")
12
Novice Struggles with Loops
Introduction
for count in range(10):
print(count)
print("Done")
count = 0
while count < 10:
print(count)
count = count + 1
print("Done")
13
Novice Struggles with Loops
Introduction
14
Novice Struggles with Loops
Introduction
15
Novice Struggles with Loops
Introduction
16
Look-Into Loops
Deepen our CS knowledge and see how that might change classroom instruction.
17
Two Types of Loops
#1 Repeat Until/While a Condition
#2 Fixed Number of Repetitions
Look-Into Loops
18
Two and a Half Types of Loops
#1 Repeat Until a Condition
#2 Fixed Number of Repetitions
#2½ Once per item in a list. (Special Case of #2)
Look-Into Loops
19
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
Fixed Number of Repeats
Conditionally Repeat
Look-Into Loops
21
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
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
Fixed Number of Repeats
Conditionally Repeat
Look-Into Loops
24
Fixed Number of Repeats
Conditionally Repeat
Look-Into Loops
25
Fixed Number of Repeats
Conditionally Repeat
Look-Into Loops
for i in range( __ ):
#
#
while _______:
#
#
26
Fixed Number of Repeats
Conditionally Repeat
Look-Into Loops
for(int i=0; i<__; i++)
{
// ...
}
while( ______ )
{
// ...
}
27
Other Loops
Look-Into Loops
for( Object o : objects )
{
// ...
}
28
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
Cognitive Load
Assessing the mental demands for completing a task.
30
Cognitive Load Theory
Long-Term Memory
Short-Term Working Memory
Cognitive Load
31
Cognitive Load Demo
Demonstration
Cognitive Load
32
Cognitive Load on Learning
Extrinsic Load
Intrinsic Load
Schema
Cognitive Load
33
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
Schema in Chess
The Chess Master wasn't seeing individual pieces, but rather recognizing common patterns… chunks!
(1973 "Perception in chess.")
Cognitive Load
35
Schema Demo
Demonstration
Cognitive Load
36
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
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
An App Inventor Loop Schema
Cognitive Load
39
A VEXcode Loop Schema
Cognitive Load
40
A Python Loop Schema
Cognitive Load
count = 0
while count < :
#
#
#
#
count = count + 1
41
A Java Loop Schema
Cognitive Load
int count = 0;
while(count < )
{
count = count + 1;
}
42
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
Known Number of Repeats
Repeat While Condition
Cognitive Load
44
In Practice
45
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
Example: CSE Activity 1.1.5
Sample Code for generating a random number of a specified length.
In Practice
47
Example: CSE Activity 1.1.5
See it with a schema…
In Practice
Repeating this many times:
48
The Loop Schema in Class
Poster
Website
Modeling
Externalizing It
In Practice
49
The Loop Schema in Class
Poster
Website
Modeling
Externalizing It
In Practice
50
The Loop Schema in Class
Poster
Website
Modeling
Externalizing It
In Practice
51
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
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
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
Thank You!
Questions?
55