Programming with Alice

Slides:



Advertisements
Similar presentations
CSC 121 Computers and Scientific Thinking Fall Conditional Execution.
Advertisements

Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Chapter 6 Horstmann Programs that make decisions: the IF command.
Introduction to Programming with Java, for Beginners Control Structures.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Adapted from slides by Marie desJardins
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
Programming With Alice. Alice Free Java based, 3D programming tool Enables the manipulation and interaction of 3D objects Can also.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Exam scores by range 3-1.
Conditional Execution
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 11 Conditional.
© Jalal Kawash Programming Peeking into Computer Science 1.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Selection Statements. Introduction Today we learn more about learn to make decisions in Turing ▫Nested if statements, ▫case statements.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Computer Science 1000 Algorithms III. Multiple Inputs suppose I ask you to write a program that computes the area of a rectangle area = length * width.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
JavaScript Controlling the flow of your programs with ‘if’ statements
UNIT 5 Lesson 15 Looping.
REPETITION CONTROL STRUCTURE
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Variables, Functions, Math, and Strings
Brent M. Dingle Texas A&M University Chapter 6, Sections 1 and 2
Python: Control Structures
Welcome to Computer Science Jeopardy
Programming Mehdi Bukhari.
EGR 2261 Unit 4 Control Structures I: Selection
IF statements.
( Iteration / Repetition / Looping )
Agenda Control Flow Statements Purpose test statement
Microsoft Visual Basic 2005 BASICS
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Conditional Statements
Conditions and Ifs BIS1523 – Lecture 8.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Introduction to pseudocode
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Logical assertions assertion: A statement that is either true or false. Examples: Java was created in The sky is purple. 23 is a prime number. 10.
Bools & Ifs.
Loops CIS 40 – Introduction to Programming in Python
Coding Concepts (Basics)
Selection Statements.
Conditional Execution
Microsoft Visual Basic 2005: Reloaded Second Edition
Conditional Logic Presentation Name Course Name
ICT Programming Lesson 3:
'Boolean' data type.
Instructor: Craig Duckett
Building Java Programs
Simple Branches and Loops
Angles on a straight line Vertically opposite angles
Chapter 11 Conditional Execution
Selection Statements Chapter 3.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Computers and Scientific Thinking David Reed, Creighton University
Presentation transcript:

Programming with Alice Decision Structures

Programming with Alice Decisions Structures Up until now, our programs have followed our instructions in the order we gave them The program follows the commands in the order they are given They may occur at the same time, but always in the same order This is known as SEQUENTIAL PROGRAMMING It fine as a method, but this means our program will always give the same result Step 3a and Step 1 Step 2 Start Step 4 End Step 3b

Programming with Alice Decisions Structures In most programs however, we want the computer to behave differently depending on the conditions To make the computer respond in different ways, the program needs to offer choices The simplest choices have two options, usually expressed as a pair of opposites: Yes/No Left/Right or True/False

Programming with Alice Decisions Structures We want our program to follow: One set of commands for a given circumstance Another set of commands for a different circumstances This is done with a DECISION STRUCTURE all decisions in the computer are based on the idea of IF/ELSE decision structure IF this is true, do COMMAND A ELSE [this is false (not true)], do COMMAND B

Programming with Alice Decisions Structures In Alice, it looks like this… IF condition is true, do Command #1 Else, do Command #2 CONDITION IF/ELSE Structure

Programming with Alice Decisions Structures IF/Else will only work with a true/false case Therefore, our CONDITION must be a true/false value This is called a BOOLEAN VALUE Boolean values can be: A BOOLEAN VARIABLE The result of a BOOLEAN FUNCTION

Programming with Alice Decisions Structures Boolean Variables Recall that a variable is a named location in the computer's memory which stores useful information. A Boolean variable stores a Boolean value True or False A boolean variable is often used to store the answer to a question that can be answered using a Boolean value (i.e., only two possible answers) We try to name our variables to reflect the question. Question Boolean Variable Do you want a cookie? wantCookie Do you wish to exit this program? readyToExit Has the user entered a valid password? validPassword

Programming with Alice Decisions Structures Boolean Functions Recall that functions are a special type of method that return a value. This value can be a number, string, or Boolean. Alice includes many primitive functions that return Boolean values Notice that many of them could easily be phrased as a question, where the answer could be Yes/No, or True/False. Many Boolean functions can be identified by their use of the word, “is”, in order to form their question e.g.

Programming with Alice Decisions Structures For example, suppose we have a penguin trying to jump through a hole in the ice to reach the water below. This plan will work fine if the hole in the ice is big enough. If the hole is too small (or the penguin is too big) then the penguin won't be able to go for a swim If the hole is wider than the penguin penguin falls down into the hole Else penguin says “Drats!” End If The condition, in this case, is whether or not the hole is wider than the penguin. Notice that there is no possibility for both actions to be performed It is one or the other. Notice how we have used indenting to separate the branches of the decision statement. Indenting is a good practise to help keep our code, or pseudocode, visually clear and organized. A Pseudocode version of this program might look something like this