Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: “If the alarm goes off,

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

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.
3-1 Chapter 3 Flow of Control (part a - branching)
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
While Loops. Challenge: ● Ask the user a simple math questions ● Continue asking the question until the user gets it right.
Selection (decision) control structure Learning objective
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
COMP 14: Looping (part 2) May 31, 2000 Nick Vallidis.
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
CSC 204 Programming I Loop I The while statement.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
Chapter 5 Logic; Got Any?. Flow of Control The order in which the computer executes statements in a program Control Structure A statement used to alter.
April 8, 1998CS102-02Lecture 2-2 Control Structures in Java I CS Lecture 2-2 Controlling Java.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Algorithms Writing instructions in the order they should execute.
CONTROL FLOW The order in which blocks are executed is called the “control flow” of the script So far all our scripts have just executed blocks in the.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
CSC 107 – Programming For Science. Today’s Goal  Know how to use and write for loops  Explain why to use for, while, & do-while loops  Convert between.
11 PART 2 ARRAYS. 22 PROCESSING ARRAY ELEMENTS Reassigning Array Reference Variables The third statement in the segment below copies the address stored.
Controlling Program Flow with Decision Structures.
Expressions Methods if else Statements Loops Potpourri.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
Pascal Programming George Boole, a 19 th Century mathematician, is created with true, false logic. A Boolean expression in Pascal will be true or false.
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Decisions: Conditional Statements (informally called If Statements) IST 256 Application Programming for Information Systems.
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.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
 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.
Follow up from lab See Magic8Ball.java Issues that you ran into.
CONTROL STATEMENTS if-then, if-then-else, switch/case For, While, Do-while, goto Break, continue.
Two Bags of Jellybeans I have two bags A and B. Both contain red and yellow jellybeans.   There are more red jellybeans in bag A than in bag B. If I choose.
Computer Science 210 Computer Organization
Sequence, Selection, Iteration The IF Statement
Section 7.1 Logical Operators
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
CiS 260: App Dev I Chapter 4: Control Structures II.
Expressions and Control Flow in JavaScript
Lesson 9: "if-else-if" and Conditional Logic
While Loops Chapter 3.
And the text with form..
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
2-1 Making Decisions Sample assignment statements
The C++ IF Statement Part 2 Copyright © Curt Hill
Computers & Programming Languages
Loops A portion of a program that repeats a statement or a group of statements is called a loop. The statement or group of statements to be repeated is.
Lecture Notes – Week 3 Lecture-2
Computer Science 210 Computer Organization
Practice with loops! What is the output of each function below?
TRUTH TABLES.
Conditional Logic Presentation Name Course Name
ICT Programming Lesson 3:
Lecture 5 Binary Operation Boolean Logic. Binary Operations Addition Subtraction Multiplication Division.
Thought for the Week: It’s okay not to win..
Truth tables Mrs. Palmer.
Simple Branches and Loops
PROGRAM FLOWCHART Iteration Statements.
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.
Decision Statements.
boolean Expressions Relational, Equality, and Logical Operators
Presentation transcript:

Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: “If the alarm goes off, I hit the snooze button” “If I don’t have coffee, then Watch Out!” “If the Red Sox win, then I am happy else I am sad”

Conditionals in BYOB Conditionals evaluate the conditional expression to determine if it is TRUE or FALSE

Conditional Expressions in BYOB Are either TRUE or FALSE at that instant Pointed at both ends 3

Conditional Examples

Booleans & Compound Conditionals More than one conditional expression “If the Red Sox win or the Yankees lose, I am happy” “If the Red Sox win and the Yankees lose, I am very, very happy!” The following are Boolean expressions: ‘And’ – Both Expressions are true ‘Or’ – At least one expression is true ‘Not’ – If it’s true, then it becomes false; if it’s false, then it becomes true

Compound Conditional Example

Conditional controls Other controls use conditions, too

Classwork Count up from 1 to 10 Use OR Use a variable keep track of where you are Output the numbers using: Now count down from 10 to 1 Use the conditional loop you didn’t use above Now count up from 1 to 10, outputting only even numbers (using any method)