Execution Control with If/Else and Boolean Questions Part 1 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

Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
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.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Introducing While loops (and random numbers too) Alice.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions 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.
Functions Alice.
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.
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.
Lesson thirteen Conditional Statement "if- else" ©
Programming: Simple Control Structures Sec 46 Web Design.
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.
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.
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Design and Implementation
Checking for Collisions: Using Functions in Alice
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.
CS 1111 Introduction to Programming Spring 2019
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
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
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 Questions Part 1 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 questions methods

Example: Boolean Question Suppose you are building a simulation system used to train flight controllers. One of the tasks of a flight 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 question that checks the vertical distance against a minimum difference in altitudes. The question 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

Vertical distance To find the difference in altitude, we use the built-in distance above question. We don't know which aircraft is above the other. To avoid a possible negative value, we take the absolute value of the distance. Note: The nesting of tiles acts like parentheses in math expressions.

Using a relational operator Use the < relational operator from the World's built-in questions to check the vertical distance against a minimum.

Calling the question The Boolean question, isTooClose is called as the condition for avoiding a collision.

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 Demonstration of the fly space collision simulation. Note: This example illustrates three decisions one in a Boolean question one that controls whether a method is called one that determines which set of instructions are immediately executed