Decisions with if statements. Simple If Statements if (age < 18) g.drawString(You may not vote., 50, 50); Evaluating a single expression.

Slides:



Advertisements
Similar presentations
CSC 121 Computers and Scientific Thinking Fall Conditional Execution.
Advertisements

Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
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.
Chapter 4: Control Structures I (Selection)
Chapter 4 - Control Statements
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.
Expressions, Equations, Inequality By: :] BenchmarkBenchmark MA Solve linear equations& inequalities with One (1) variable using algebraic methods,
Selection Statements Make a decision based on conditions Allows the computer to be intelligent.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Introduction to Relational Database Systems 1 Lecture 4.
Age limits – Section 1. From birth Have your own passport Have your own passport Have a bank account Have a bank account.

Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
The IF function Bernard Liengme. Objectives To know how to: Construct a condition using the comparison operators =, >=, >, ; Construct a formula using.
Selection in Python If statements.
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Logical Operators and While Loops CS303E: Elements of Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Numbers in the Real World.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Lecture 3: Control Structures - Selection BJ Furman 10SEP2012.
Selection Victor Norman CS104 Calvin College. Reading Quiz Counts toward your grade.
Neal Stublen Human Decisions  Think about a decision you've made today?  How did you arrive at that decision?  Was it a black-and-white.
Playing computer with logic problems Please use speaker notes for additional information!
The conditional statement
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
General Computer Science for Engineers CISC 106 Lecture 33 Dr. John Cavazos Computer and Information Sciences 05/11/2009.
CS 1400 Jan 2007 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ for Engineers and Scientists Third Edition
Algebra: Variables and Expressions variable A variable is a letter or symbol that represents an unknown quantity (a number). ALGEBRA. The branch of mathematics.
IDK0040 Võrgurakendused I harjutus 07: PHP: Operators, Switch, Forms Deniss Kumlander.
Decisions – Chapter 3 IPC144 Week 2. IPC144 Introduction to Programming Using C Week 2 – Lesson 2 (Pages 12 to 18 in IPC144 Textbook)
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
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.
Chapter 4: Control Structures I
CMSC 104, Version 8/061L11Relational&LogicalOps.ppt Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else.
Conditionals & boolean operators
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.
Simple Control Structures IF, IF-ELSE statements in C.
Lesson 5: Working with Formulas and Functions Logical and 3D Formulas.
Objective - To subtract integers. To subtract an integer is to add its opposite. a - b =a + -b = (-5) =8 + 5 = = 4 Rewrite the.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Control Structures 1. Control Structures Java Programming: From Problem Analysis to Program Design, D.S. Malik 2.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
1 2. Program Construction in Java. 2.4 Selection (decisions)
PHP-language, conditional statements Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
2.3 Multiplying Rational Numbers The product of numbers having the same sign is positive. The product of numbers having different signs is negative.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
IST 210: PHP Logic IST 210: Organization of Data IST2101.
CHAPTER 4 DECISIONS & LOOPS
Sequence, Selection, Iteration The IF Statement
Addition/ Subtraction
Assignment statement:
Operator Precedence Operators Precedence Parentheses () unary
Chapter 4: Decision Structures and Boolean Logic
ICS 3U Tuesday, September 21st.
Chapter 4: Decision Structures and Boolean Logic
Conditional Logic Presentation Name Course Name
Algebra: Variables and Expressions
Relational Operators.
Selection Structures: Single-alternative
Decision making and control functions
Programming Control Structures with JavaScript
Relational and Logical Operators
Chapter 3: Selection Structures: Making Decisions
Relational and Logical Operators
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

Decisions with if statements

Simple If Statements if (age < 18) g.drawString(You may not vote., 50, 50); Evaluating a single expression

Simple If Statements if (age > 18) g.drawString(You may vote., 50, 50); Evaluating a single expression

Simple If Statements if (age >= 18) g.drawString(You may vote., 50, 50); Evaluating a single expression

Simple If Statements if (age != 16) g.drawString(You are not sixteen years old., 50, 50); Evaluating a single expression

Simple If Statements if (age == 16) g.drawString(You are sixteen years old., 50, 50); Evaluating a single expression

Logical Opereators >Greater than <Less than ==Equal to !=Not equal to <=Less than or equal to >=Greater than or equal to

Equal Signs =This is used to assign values to variables. int sliderValue = 0; ==This is used to compare values. if (age == 16)

Multiple Comparisons if (age >= 21 && age < 65) g.drawString(You may be an airline pilot., 50, 50); Evaluating multiple expressions

Multiple Comparisons if (age = 65) g.drawString(You may not be an airline pilot., 50, 50); Evaluating multiple expressions

If-Else Statements if (age < 18) g.drawString(You may not vote., 50, 50); else g.drawString(You may vote., 50, 50); Using Else with If statements

If-Else Statements if (age = 65) g.drawString(You may not be an airline pilot., 50, 50); else g.drawString(You may be an airline pilot., 50, 50); Using Else with If statements

Grouping Statements if (age < 18) { g.drawString(You may not vote., 50, 50); g.drawString(You may not serve in the military., 50, 50); g.drawString(You may not sign business contracts., 50, 50); } else { g.drawString(You may vote., 50, 50); g.drawString(You may serve in the military., 50, 50); g.drawString(You may sign business contracts., 50, 50); } Grouping statements with braces