Algorithms: Branching and Iteration (in Scratch)

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4: Control Structures I (Selection)
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Control Flow C and Data Structures Baojian Hua
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Chapter 8 (Control Structure) Slide 1 Control Structures Control structures are used by the programmer to incorporate the desired sequence of execution.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
The If/Else Statement, Boolean Flags, and Menus Page 180
C++ for Engineers and Scientists Third Edition
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Running Time Big O Notation.
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
1 2. Program Construction in Java. 2.4 Selection (decisions)
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
CSCI 161 Lecture 7 Martin van Bommel. Control Statements Statements that affect the sequence of execution of other statements Normal is sequential May.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
September 7, 2004ICP: Chapter 3: Control Structures1 Introduction to Computer Programming Chapter 3: Control Structures Michael Scherger Department of.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Lesson thirteen Conditional Statement "if- else" ©
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Chapter 7 JavaScript: Control Statements, Part 1
Introduction to C++ Programming Language
JavaScript: Control Statements I
JavaScript: Control Statements.
Control Structures.
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Selection Statements.
Computer Science Core Concepts
Chapter 4: Control Structures I (Selection)
Conditional Statements
ICT Programming Lesson 3:
if-else Structures Principles of Engineering
PHP CONDITIONAL STATEMENTS
Presentation transcript:

Algorithms: Branching and Iteration (in Scratch) © 2014 Project Lead The Way, Inc. Unpublished work © 2013 Project Lead The Way, Inc.

Learn from Scratch! http://scratch.mit.edu/projects/11516969/ Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Learn from Scratch! http://scratch.mit.edu/projects/11516969/ Edit your picture in paint editor

Algorithms are step-by-step procedures Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Algorithms are step-by-step procedures

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

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

If-else structure Continues with next block Presentation Name Course Name Unit # – Lesson #.# – Lesson Name If-else structure Continues with next block

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

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.

Iteration Iteration: an algorithm that repeats, Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Iteration Iteration: an algorithm that repeats, one cycle after another

Your turn! Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Your turn!

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

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

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

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