Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2009ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
© 1999, by Que Education and Training, Chapter 6, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
1 Fall 2007ACS-1903 Chapter 3 Decision Structures The if Statement The if-else Statement The if-else-if Statement Nested if Statements Logical Operators.
Fall 2009ACS-1805 Ron McFadyen1 Functions A function is a collection of statement, similar to a method, but a function is defined to return a value to.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
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 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 7 Repetition.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 8 Recursion.
Fall 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
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.
Fall 2009ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
More About Recursion Alice. A second form of recursion A second form of recursion is used when the solution to a problem depends on the ability to break.
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 4 OO Programming Concepts.
Execution Control with If/Else and Boolean Functions Example: Single Condition Alice.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming.
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 Functions
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.
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.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
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.
© Jalal Kawash Programming Peeking into Computer Science 1.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Mathematical Expressions, Conditional Statements, Control Structures
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Fall 2009ACS-1805 Ron McFadyen1 Chapter 2 Program Design & Implementation.
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.
Xiaojuan Cai Computational Thinking 1 Lecture 7 Decision Structure Xiaojuan Cai (蔡小娟) Fall, 2015.
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.
Lesson thirteen Conditional Statement "if- else" ©
Programming: Simple Control Structures Sec 46 Web Design.
Fall 2008ACS-1805 Ron McFadyen1 Event-driven programming Chapter 5 covers event-driven programming. Events are user or condition driven and so each event.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
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.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Execution Control with If/Else and Boolean Functions
Control Structures.
Programming: Simple Control Structures
Graphical User Interfaces in Java Event-driven programming
Programming with Alice
Program Flow.
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.
The structure of programming
Chapter 3: Selection Structures: Making Decisions
Thinking procedurally
Event-driven programming
Presentation transcript:

Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else

Fall 2007ACS-1805 Ron McFadyen2 Functions & If/Else A function is similar to a method in that it has a name, instructions, and possibly parameters, but differs in that a function returns a value (to be used from where it was called). An If/Else is a decision control structure (a special type of instruction) that results in exactly one, out of two groups of instructions, to be executed. Which group is executed is determined by the value of an expression (that can involve the computation of a function).

Fall 2007ACS-1805 Ron McFadyen3 Functions Alice provides built-in functions, and allows you to write your own

Fall 2007ACS-1805 Ron McFadyen4 Functions Suppose we want the alienOnWheels to move to the rock. Suppose the distance to move is the distance separating the two less one metre. Consider a move instruction that utilizes the value returned by the distance to function Function returns a value Expression (value passed to move)

Fall 2007ACS-1805 Ron McFadyen5 Writing Your Own Functions Notice the available statements Return statement

Fall 2007ACS-1805 Ron McFadyen6 If / Else The effect of an If/Else is often illustrated with the following diagram conditio n Action AAction B Depending on the value of condition, exactly one of Action A or Action B is executed truefalse

Fall 2007ACS-1805 Ron McFadyen7 Nested If / Else The effect of an If/Else is often illustrated with the following diagram conditio n Action AAction B Depending on the value of condition, exactly one of Action A or Action B is executed truefalse

Fall 2007ACS-1805 Ron McFadyen8 Tips/Techniques Random Numbers