PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.

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

Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
While loops.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Conditional Statements Control Structures.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Visual C++ Programming: Concepts and Projects
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Decision Structures and Boolean Logic
CHAPTER 4: CONDITIONAL STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Relational Operators Relational operators are used to compare two numeric values and create a boolean result. –The result is dependent upon the relationship.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
B. RAMAMURTHY Lab1 Discussion. General Instructions Attend the recitation (s), office hours (s) to get help Read the Lab description Understand what is.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Copyright 2003 Scott/Jones Publishing Making Decisions.
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
03 August 2004 NLP-AI Java Lecture No. 4 Operators & Decision Constructs Satish Dethe.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Lesson Two: Everything You Need to Know
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Expressions Methods if else Statements Loops Potpourri.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Chapter 3: Decisions and Loops
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Simple Control Structures
Chapter 4: Decision Structures and Boolean Logic
Control Structures.
JavaScript Selection Statement Creating Array
IF if (condition) { Process… }
For Net Art Lecture 2 J Parker
Control Structures: Selection Statement
Chapter 4: Decision Structures and Boolean Logic
Pages:51-59 Section: Control1 : decisions
Conditional Logic Presentation Name Course Name
Decision I (if Statement)
CHAPTER 4: Conditional Structures
Understanding Conditions
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Control Structures: Selection Statement
Pages:51-59 Section: Control1 : decisions
Chapter 4: Decision Structures and Boolean Logic
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Presentation transcript:

PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions

Introduction There are situations where you make a decision and select alternative paths in execution. “if” statements in Processing help you implement this in your program “if” is also called “selection” statement We will look at the “syntax” or “structure” of the “if” statement and its “semantics” or meaning.

“if” syntax and semantics if (test) { statements} Meaning: if test is “true” then execute the statements If the test is “false” then skip the statements and go the statement after the “if” statement. “test” is a condition expressed using relational exapressions Example: if (x > width) { x = 0;}

“if..else” statement Syntax: if (condition) { statements 1 } else { statements 2 } Example: if (x <= width) { x = x + 1;} else // we assume x > width { x = 0; }

Conditions How to write the conditions? Conditions evaluate to Boolean value of true or false Operators you can use to write conditions are: > greater than < less than >=, < = == equality != not equal to || logical or && logical and ! Logical not We will learn these as we go along using examples See p.54 for if semantics

Lets look at some examples Define x as an integer. Initialize it to a random value. Hmm.. how to generate a random number in Processing? (int)random(range) Let the random number be in the range 0-width of the canvas. Repeat the same for a variable y. But random number is Draw a line between x,y and mouseX, mouseY If x > y stroke color is black Else stroke color is white Let the background be blue.