Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.

Slides:



Advertisements
Similar presentations
AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
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.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
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.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
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 Alice.
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.
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming.
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.
Recursion1 Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Jan 2010 Recursion in Alice.
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.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Functions Alice.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Mathematical Expressions, Conditional Statements, Control Structures
ActionScript: Functions, Parameters, Functions that return a value, Variables, setInterval Functions MMP 220 Multimedia Programming This material was prepared.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
Classes, Objects, and World-level Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
ActionScript: Classes, Properties, EventHandler Methods, Datatypes & Control Structures MMP 220 Multimedia Programming This material was prepared for students.
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.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
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
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.
Interactive Programming MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project.
Programming: Simple Control Structures Sec 46 Web Design.
Parameters MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded.
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.
Programming: Simple Control Structures
Programming: Simple Control Structures
Recursion Alice.
While: Indefinite Loops
Simple Control Structures
Recursion Alice.
Programming: Simple Control Structures
Creating an Animation Program
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Design and Implementation
Animation Programs: Scenarios and Storyboards
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.
Computer Science Core Concepts
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
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.
Functions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded by National Science Foundation grant # Co PI’s Christopher Stein and Jody Culkin BMCC CUNY The material in this handout is taken from “Learning to Program with Alice” a project supported by the National Science Foundation under Grant NSF , NSF , and NSF Contact Wanda Dann: Stephen Cooper: Randy Pausch: and Don Slater:

Control Statements We 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 – repetition

Conditional Execution Conditional execution is where some condition is checked and a decision is made about whether a block of the program will be executed. Conditional execution is extremely useful in – games – simulations – real-time controls, e.g. robot systems

Example As a simple example of conditional execution, let's revisit the FirstEncounter world. – As the robot moves closer, the alien hides behind the rocks. – We want to check a condition (is robot to short to over the rock?) and then perform an action based on the whether the condition is true.

If/Else In Alice, an If/Else control statement is used to check a condition and make a decision.

Storyboard A storyboard design for this conditional statement is: The condition in an If statement is a Boolean function that yields a true or false value. If spiderRobot is shorter than rock Do in order spiderRobot neck move up spiderRobot neck move down Else Do nothing

Demo Ch03Lec2FirstEncounterIfElse Concepts illustrated in this example program: – The condition of an If/Else statement is constructed by using a function that returns a Boolean value (true or false). – Do nothing in the Else part of the statement means that if the condition is false, Alice will skip this part and go to the next instruction.

A different scenario In some cases, the built-in functions are not sufficient for a condition that we want to check. – For example, the built-in function is shorter than compares the heights of two objects. – Suppose, however, that we wanted to compare the robot's height to 2 meters. – How can we compare the height of the robot 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 functions.

Demo Ch03Lec2FirstEncounterRelationalOps Concepts illustrated in this example program: – Relational operations are defined using the world's built-in functions. – Placeholder values are first selected for the "a" and "b" components of the relational expression. Then the placeholder values are each replaced by either a function or a number.

Need for Repetition The walking action is not realistic: the robot moves forward to the rock (a distance of several meters) but the legs are simulating a walking action only once.

One meter, one step A more realistic action is to move the robot forward one meter for each step made by the legs. But, now the robot is moving forward only 1 meter. This block of code will have to be repeated again and again to animate the robot moving close to the rock.

Loop The Loop statement is a simple control structure that provides for repeating an instruction (or block of instructions) a counted number of times.

Demo Ch03Lec2FirstEncounterLoop

Demo Ch03Lec1FirstEncounterExpressionV2 Subtracting 2 meters from the distance is an arbitrary amount. To be more precise, we could subtract the width of the rock. The resulting expression subtracts the value of one function from the value of another function.

Assignment Read Chapter 3