PowerPoint Name

Algorithms:
Branching and Iteration
(in Scratch)
Computer Science and Software Engineering
© 2014 Project Lead The Way, Inc.
Learn from Scratch!
http://scratch.mit.edu/projects/11516969/
Edit your picture in paint editor
Algorithms are step-by-step procedures
If-else structure: conditional
• Always evaluates
condition at top of
the if-else structure
• Boolean expression:
true or false
If-else structure
• Executes one chunk
or the other
• If-else always
executes one chunk:
not zero, not two
• If (no else) might
execute one or zero
chunks
If-else structure
• Continues with next
block
Stacked if-else-structures
• These are separate structures,
one after another
y
240
snap
squeak
-240
clap
squeak
240
0
snap
sing
-240
clap
sing
x
Nested if-else-structures
• One inside the other
y
240
clap
Hello
-240
squeak
Fella
240
0
snap
Hello
-240
sing
Fella
x
Iteration
• Iteration: an algorithm that repeats,
one cycle after another
Your turn!
Don’t miss the “else” opportunity
• These stacks run slightly differently. Why?
Better
Usually wasteful, risky
Pair of opposite conditions
How to get exactly-one-of-several
• If-else selects 1-of-2
• If-elseif-else selects 1-of-3
10
20
30
How to get exactly-one-of-several
• How about 1-of-4?
1-of-4 ?
1-of-3
if
if
else-if
else-if
else-if
else
10
else
20
30
How to get exactly-one-of-several
1-of-5
if
else-if
else-if
else-if
else
10
20
30
40