Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.

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

While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Introducing While loops (and random numbers too) Alice.
Fall 2007ACS-1805 Ron McFadyen1 Functions and if-else A function is a collection of statement, similar to a method, but a function is defined to return.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Execution Control with If/Else and Boolean Functions
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Alice: Functions Alice Chapter 6 September 19, 2005.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Execution Control with If/Else and Boolean Functions Alice.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Functions Alice.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Chapter 6.2 Execution Control with If/Else and Boolean Functions.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Programming: Simple Control Structures
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Programming: Simple Control Structures Sec 46 Web Design.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Computer Science Up Down Controls, Decisions and Random Numbers.
Obj: to recognize built-in functions and expressions HW: Read Section 3.1 and do HW4 Edmodo article due Sunday at 8pm Edmodo feedback due 8pm 10/17 Do.
Functions Sec 51 Web Design.
Programming: Simple Control Structures
Execution Control with If/Else and Boolean Functions
Programming: Simple Control Structures
Simple Control Structures
Functions Sec 8-11 Web Design.
Microsoft Visual Basic 2005 BASICS
Programming: Simple Control Structures
IF if (condition) { Process… }
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Design and Implementation
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Conditionals Exploring Computer Science Lesson 4-9.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Exploring Computer Science Lesson 4-8
Programming: Simple Control Structures
Functions Alice.
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Decision Statements.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Execution Control with If/Else and Boolean Functions Example: Single Condition Alice

Thinking About More Advanced Worlds No doubt you have started to think about building animations like simulations and video games… To build more advanced worlds, you will need to write code that involves decisions

Examples of Decisions In a car-race simulation, the driver steers the car around curves and past mile-markers. If the car stays on the road, the score increases. If the car goes off the road into the stands, the car crashes. If the driver gets the car over the finish-line, the time is posted and the driver wins!

Logical Expressions A decision is made based on current conditions A condition is checked in a logical expression that evaluates to true or false (Boolean) value car on road true car over finish line false

If/Else In Alice, a logical expression is used as the condition in an If/Else control structure. Decisions (using If/Else) are used in functions methods

Example: Boolean Function Suppose you are building a simulation system used to train air traffic controllers. One of the tasks of an traffic controller is to be alert for possible collisions in the flight space.

Storyboard One factor in determining whether two aircraft are in danger of collision is the vertical distance (difference in altitudes) between them. We can write a function that checks the vertical distance against a minimum difference in altitudes. The function returns true if they are too close, otherwise false. isTooClose Parameters: aircraftOne, aircraftTwo, minimumDistance If the vertical distance between aircraftOne and aircraftTwo is less than minimumDistance return true Else return false

Demo Ch06Lec2aFlightCollision-V1 Concepts illustrated in this example A world-level relational operator is used to create a Boolean expression as the condition. The absolute value function is used to make sure the computed difference in altitude is not a negative number.

Storyboard To avoid a collision, the aircraft that is above the other should move up and the lower aircraft should move down. avoidCollision Parameters: aircraftOne, aircraftTwo If aircraftOne is above aircraftTwo Do together aircraftOne move up aircraftTwo move down Else Do together aircraftOne move down aircraftTwo move up

Demo Ch06Lec2aFlightCollision-V2 Concepts illustrated in this example Decisions were made to control whether a method is called determine which set of instructions are immediately executed