Programming: Simple Control Structures Part 1 – Conditional Execution Alice.

Slides:



Advertisements
Similar presentations
Recursion Alice.
Advertisements

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.
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.
While: Indefinite Loops Sec 8-14 Web Design. Objectives The student will: Understand what an Indefinite Loop is Understand how create an indefinite loop.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Introducing While loops (and random numbers too) Alice.
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: Putting Together the Pieces Built-in Functions and Expressions 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.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
Recursion Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we know is that repetition.
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 Sec 52 Web Design.
Execution Control with If/Else and Boolean Questions Part 1 Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
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.
© The McGraw-Hill Companies, 2006 Chapter 2 Selection.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
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.
Today’s Agenda 1.Collect Pre-Lab 3 2.Alice Programming Assignment 3.Built-in Functions 4.Expressions 5.Control Structure 6.Assign pair programming teams.
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.
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.
Programming: Simple Control Structures Sec 46 Web Design.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Programming: Simple Control Structures
Execution Control with If/Else and Boolean Functions
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
Recursion Alice.
While: Indefinite Loops
Simple Control Structures
Recursion Alice.
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Functions Alice.
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Programming: Simple Control Structures Part 1 – Conditional Execution Alice

Control Statements You have been using Do in order and Do together to control the way instructions are executed in your Alice program. Control statements can also be used for conditional execution whether or not an instruction(s) is executed repetition execution of the same instruction(s) more than once This session will focus on conditional execution.

Conditional Execution A conditional execution is where some condition is checked and a decision is made about whether a section (block) of the program will be executed. Conditional execution is an extremely useful program component in games simulations real-time controls, for example robot systems

Example As a simple example of conditional execution, let's revisit the Egyptian scene in the Hollywood movie set. The camera angle can mislead our perception of the scene Which is taller – the mummy or the pharoah?

If/Else We need to check a condition (is the mummy taller than the pharoah?) and then perform an action based on the whether the condition is true. In Alice, an If/Else control statement is used to check a condition and make a decision.

Storyboard In our example, we can demonstrate which person is the tallest by having that person turn around. A design for this action is: The condition in an If statement is a question that yields a Boolean (true or false) value. In this example, is taller than is a built-in question. If mummy is taller than pharoah mummy turns 1 revolution Else pharoah turns 1 revolution

Demo Develop program in classroom demonstration.

Caution! Checking a condition can be tricky because it is easy to forget about some possibility. In our example, we tested for whether the mummy is taller than the pharoah. If not, we assumed that the pharoah was taller than the mummy. What if the pharoah and the mummy are of equal heights?

Nested Ifs To resolve this issue, we can use two If statements, one inside the other (we call this nested Ifs). A storyboard: If mummy is taller than pharoah mummy turn 1 revolution Else If pharoah is taller than mummy pharoah turn 1 revolution Else Do together mummy turn 1 revolution pharoah turn 1 revolution

Demo Modify program in classroom demonstration

A different scenario In some cases, the built-in questions are not sufficient for a condition that we want to check. For example, the built-in question is taller than compares the heights of two objects. We used this question to compare the heights of the mummy and the pharoah. Suppose, however, that the casting call for the mummy requires that the actor is than 2 meters tall. How can we compare the height of the mummy to a specific measurement (2 meters)?

Relational Operators In situations where you need to write your own comparison, you can use a relational operator. Relational operators are provided in the World's built-in questions.

Using a relational operator To demonstrate whether the mummy's height is more than 2 meters, we can use the > operator:

Assignment Read Chapter 3-2 (through p. 66), Simple Control Structures – Conditional Execution Lab 3-2 (part 1)