Execution Control with If/Else and Boolean Functions

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

Parallel and Distributed Simulation
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Introducing While loops (and random numbers too) Alice.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
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.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Alice: Functions Alice Chapter 6 September 19, 2005.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
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.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
Execution Control with If/Else and Boolean Functions Alice.
Variables and Inheritance A More Complex Example Alice.
Functions Alice.
Game Maker Terminology
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Chapter 6.2 Execution Control with If/Else and Boolean Functions.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
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.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
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.
Controlling Program Flow with Decision Structures.
Programming: Simple Control Structures Sec 46 Web Design.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
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.
Programming: Simple Control Structures
Execution Control with If/Else and Boolean Functions
Variables and Inheritance Part 2
Programming: Simple Control Structures
Simple Control Structures
Microsoft Visual Basic 2005 BASICS
Lesson 8: Boolean Expressions and "if" Statements
Programming: Simple Control Structures
Parallel and Distributed Simulation
Programming: Simple Control Structures
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Design and Implementation
Interactive Programming
Programming: Simple Control Structures
Programming: Simple Control Structures
ICT Gaming Lesson 3.
An Introduction to Linux
Programming: Simple Control Structures
Programming: Simple Control Structures
Interactive Programming
Decision Statements.
Variables and Inheritance A More Complex Example
Presentation transcript:

Execution Control with If/Else and Boolean Functions Alice

Adding More Complexity to Worlds Initially programs were not interactive program ran and user watched Then learned how to make programs interactive add events to program when event occurs an event handler method is called adds variability to programs not always the same thing happening

Event Driven Programming a whole philosophy of programming called “event driven” programming flow of program controlled by external events as opposed to things internal to the program very important in user interfaces the parts of programs that interact with real users think about using a computer the operating system ( Windows XP, Mac OS X, etc. ) has a large component that is event driven responding to your actions. (Move mouse, click, type)

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 A race car simulation driver provides input from steering wheel, gas pedal, and brake if car stays on road display next section of road if car hits another car, crash if car goes too far off road, crash if pass checkpoints, more time

Logical Expressions Program must make decision based on current conditions on road? time left? intersected another car?

Logical Expressions A condition is checked in a logical expression that evaluates to Boolean value 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 Lab12FlightCollision-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 aircraftOne move down aircraftTwo move up

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