Download presentation
Presentation is loading. Please wait.
Published byAugustus Harvey Modified over 9 years ago
1
Algorithms: Branching and Iteration (in Scratch)
© 2014 Project Lead The Way, Inc. Unpublished work © 2013 Project Lead The Way, Inc.
2
Learn from Scratch! http://scratch.mit.edu/projects/11516969/
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Learn from Scratch! Edit your picture in paint editor
3
Algorithms are step-by-step procedures
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Algorithms are step-by-step procedures
4
If-else structure: conditional
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name If-else structure: conditional Always evaluates condition at top of the if-else structure Boolean expression: true or false
5
If-else structure Executes one chunk or the other
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name 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
6
If-else structure Continues with next block Presentation Name
Course Name Unit # – Lesson #.# – Lesson Name If-else structure Continues with next block
7
Stacked if-else-structures
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Stacked if-else-structures These are separate structures, one after another -240 240 x y snap sing squeak clap
8
Nested if-else-structures
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Nested if-else-structures One inside the other -240 240 x y snap Hello clap squeak Fella sing Within the outer if-else structure, one group of blocks or the other is executed. Each of the two options here contains an if-else structure plus one more block. In each case, the “if” or “else” section will execute and then the group continues with a block to say something. Then the script could continue below the outer if-else structure.
9
Iteration Iteration: an algorithm that repeats,
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Iteration Iteration: an algorithm that repeats, one cycle after another
10
Your turn! Presentation Name Course Name
Unit # – Lesson #.# – Lesson Name Your turn!
11
Don’t miss the “else” opportunity
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Don’t miss the “else” opportunity These stacks run slightly differently. Why? Better Usually wasteful, risky Pair of opposite conditions
12
How to get exactly-one-of-several
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name How to get exactly-one-of-several If-else selects 1-of-2 If-elseif-else selects 1-of-3 10 20 30
13
How to get exactly-one-of-several
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name 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 else These structures are very common. If you want to check the user input for one of four menu items, for instance, you can use this structure. If you wanted heaters, fans, or air conditioners to come on at different temperatures, you could use this structure. The “else” block at the end is a catch-all; if none of the conditions are met, the “squeak” block executes. 10 20 30
14
How to get exactly-one-of-several
Presentation Name Course Name Unit # – Lesson #.# – Lesson Name How to get exactly-one-of-several 1-of-5 if else-if else-if else-if These structures are very common. If you want to check the user input for one of four menu items, for instance, you can wuse this structure. If you wanted heaters, fans, or air conditioners to come on at different temperatures, you could use this structure. The “else” block at the end is a catch-all; if none of the conditions are met, the “squeak” block executes. else 10 20 30 40
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.