If / Else Statements.

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 - Control Statements
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
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,
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
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.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
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,
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
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.
Control statements Mostafa Abdallah
Lesson thirteen Conditional Statement "if- else" ©
TestScore < 80 testScore * 2 >= < w / (h * h) x + y != 2 * (a + b) 2 * Math.PI * radius
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
JavaScript: Conditionals contd.
JavaScript Controlling the flow of your programs with ‘if’ statements
Introduction to Calculated Columns Variables, Conditionals, and String Manipulation PRESENTER: Cameron Blashka| Informer Implementation Specialist| April.
Control Flow (Python) Dr. José M. Reyes Álamo.
The Ohio State University
Sequence, Selection, Iteration The IF Statement
Introduction to programming in java
Operator Precedence Operators Precedence Parentheses () unary
Topics The if Statement The if-else Statement Comparing Strings
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Expressions and Control Flow in JavaScript
Javascript Conditionals.
Introduction To Robot Decision Making
JavaScript Selection Statement Creating Array
Topics The if Statement The if-else Statement Comparing Strings
Conditionals & Boolean Expressions
Expressions & Control Flow CSE 120 Winter 2018
2-1 Making Decisions Sample assignment statements
Control Structures: Selection Statement
Pages:51-59 Section: Control1 : decisions
Chapter 8: More on the Repetition Structure
Visual Basic – Decision Statements
Selection Statements.
If Statements.
Introduction To Robot Decision Making
Logic of an if statement
Conditional Statements with JavaScript
Chapter 5: Selection Statement
CS2011 Introduction to Programming I Selections (I)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Compound Conditionals
Control Structures: Selection Statement
OPERATORS AND SELECTION 2
If / Else Statements.
Programming Control Structures with JavaScript
Pages:51-59 Section: Control1 : decisions
Lecture 9: JavaScript Syntax
The boolean type and boolean operators
Conditionals.
Presentation transcript:

If / Else Statements

If and Else statements allow you to run some code based on whether a condition is true or false.

Relational Operators Logical Operators Operator When it is true... == If the first expression evaluates to something that is equal to the second expression. >= If the first expression evaluates to something that is greater or equal to the second expression > If the first expression evaluates to something that is greater than the second expression <= If the first expression evaluates to something that is lesser or equal to the second expression < If the first expression evaluates to something that is less than the second expression != If the first expression evaluates to something that is not equal to the second expression && If the first expression and the second expression both evaluate to true || If either the first expression or the second expression evaluate to true ! Flips the value from false to true or true to false Relational Operators Logical Operators

Conditional Expressions lastName == "Hopper" testScore == 10   firstName != "Grace" months != 0 testScore > 100 age < 18 distance >= limit stock <= reorder_point rate / 100 >= 0.1 Expressions evaluate to true or false.

Handy Boolean Expression The syntax of the global isNaN method isNaN() is a global method. The term “global” means it is available everywhere in your JavaScript code. Global methods are also sometimes called functions.

Conditional expressions with logical operatiors Expressions evaluate to true or false. What do each of these expressions evaluate to?

Putting conditional expressions to work! The syntax of the if statement

An if statement with multiple else clauses

An Example var speedLimit = 55; function amISpeeding(speed) { if (speed >= speedLimit) { alert("Yes. You are speeding."); } else { alert("No. You are not speeding. What's wrong with you?"); } amISpeeding(53); amISpeeding(72);

var xPos = 300; var yPos = 150; function sendWarning(x, y) { if ((x < xPos) && (y < yPos)) { alert("Adjust the position"); } else { alert("Things are fine!"); } sendWarning(500, 160); sendWarning(100, 100); sendWarning(201, 149); Your if and else statements can be nested to help you simulate more complex situations!

Challenges GuessANumber DayOfTheWeek AreasOfRectangles AgeClassifier RomanNumerals MassAndWeight MagicDates ColorMixer HotDogCookoutCalculator