Four Fundamental Pieces Instruction Control Structure Function Expression.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
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.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
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.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
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.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
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.
Execution Control with If/Else and Boolean Functions Alice.
© Jalal Kawash Programming Peeking into Computer Science 1.
Functions Alice.
Mathematical Expressions, Conditional Statements, Control Structures
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
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.
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
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.
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
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
ICT Programming Lesson 3:
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:

Four Fundamental Pieces Instruction Control Structure Function Expression

Instruction An instruction is a statement that executes (is carried out by the computer at runtime). In Object Oriented Programming, an instruction is defined as a method. In Chapter 2, we used instructions to make objects perform a certain action. Examples: snowman turn to face snowwoman spiderRobot move up 0.5 meters

Control Structure A control structure is a statement that controls which instructions are executed and in what order. In previous worlds, we used: Do in order Do together

Functions A function asks a question (to check a condition) or computes a value. In Alice, a function is used to get the information we need about the properties of objects Is the snowwoman's face red? the relationship of one object to another What is the distance between the mummy and pyramid? a current condition What key (on the keyboard) was pressed? Let's look at an example…

Built-in Functions Categories proximity size spatial relation point of view other This example illustrates some built-in proximity functions.

Values When a function is used to ask a question or perform a computation, an answer is returned. The answer is called a value. The type of value depends on the kind of function. In our example, we want to ask the question: What is the distance of the robot to the rock? We expect to get a number value. It could be a whole number or a fractional value, such as 3 meters or 1.2 meters

Types of Values In our example, we used a function that has a number value. Other types of values include: Boolean true, false String "Oh, Yeah!" Object snowman, helicopter Position in the world (0, 0, 0) – the center of an Alice world

Problem: Collision When the program is run, the robot collides with a rock. The problem is the distance between two objects is measured center-to-center. One way to avoid a collision is to subtract a small number (1 or 2) from the distance.

Expressions An expression is a math or logic operation on numbers or other types of values Alice provides math operators for common math expressions: addition + subtraction  multiplication * division /

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

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

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.

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