Lesson 8: Boolean Expressions and "if" 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

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.
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.
Python quick start guide
Programming Logic and Design Sixth Edition
Chapter 4 The If…Then Statement
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Chapter 3 Making Decisions
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
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.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Branches and Program Design
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
5.04 Apply Decision Making Structures
Controlling Program Flow with Decision Structures.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
Computer Science Up Down Controls, Decisions and Random Numbers.
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
© 2006 Lawrenceville Press Slide 1 Chapter 5 The If…Then Statement (One-Way)  Conditional control structure, also called a decision structure  Executes.
JavaScript Controlling the flow of your programs with ‘if’ statements
Visual Basic.NET Windows Programming
Introduction to Decision Structures and Boolean Variables
Collision Theory and Logic
Programming & Scratch.
Chapter 4 The If…Then Statement
Collision Theory and Logic
Introduction to Event-Driven Programming
Selection and Python Syntax
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
IF statements.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
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,
Chapter 4: Decision Structures and Boolean Logic
Lesson 9: "if-else-if" and Conditional Logic
Compound Conditional Logic
Lesson 1: Buttons and Events – 12/18
Lesson 10: Building an App: Color Sleuth
Control Structures.
Microsoft Visual Basic 2005 BASICS
Lesson 2: Multi-Screen Apps
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Topics The if Statement The if-else Statement Comparing Strings
Creativity in Algorithms
IF if (condition) { Process… }
While Loops and If-Else Structures
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Lesson 5: Building an App: Clicker Game
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Chapter 4: Decision Structures and Boolean Logic
Design and Implementation
Visual Basic – Decision Statements
Selection Statements.
Chapter 5: Control Structure
While Loops and If-Else Structures
Conditional Logic Presentation Name Course Name
ICT Programming Lesson 3:
PYTHON: BUILDING BLOCKS Sequencing & Selection
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
ICT Gaming Lesson 2.
Beginning C Lecture 3 Lecturer: Dr. Zhao Qinpei
CS2011 Introduction to Programming I Selections (I)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
CHAPTER 5: Control Flow Tools (if statement)
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

Lesson 8: Boolean Expressions and "if" Statements UNIT 5 – LESSON 8

VOCABULARY ALERT! Boolean - A single value of either TRUE or FALSE Boolean Expression - in programming, an expression that evaluates to True or False. Conditionals - Statements that only run under certain conditions. If-Statement - The common programming structure that implements "conditional statements". Selection - A generic term for a type of programming statement (usually an if-statement) that uses a Boolean condition to determine, or select, whether or not to run a certain block of statements.

Here’s what you will do: Write and test conditional expressions using comparison operations Given an English description write code (if statements) to create desired program logic Use the comparison operators (<, >, <=, >=, ==, !=) to implement decision logic in a program. When given starting code add if, if-else, or nested if statements to express desired program logic

PRACTICE, PRACTICE, PRACTICE!

In everyday conversation, it is common to interchange the words “when” and “if,” as in “If the user presses the button, execute this function.” The English language is tricky. We often say “if” the button is clicked when really we mean “when” a button is clicked. This can cause confusion because “if” has a well-defined meaning in programming.

How are conditionals (if statements) different from events? Events are setup by a programmer, but triggered by the computer at any momement in time. If statements are a way a programmer can have her code make a decision during the normal flow of execution to do one thing or another.

As we have already seen in prior lessons, an if statement is evaluated when the code reaches a particular line and uses a true/false condition (like a comparison between values e.g., score == 5), to decide whether to execute a block of code.

As we begin to write event-driven programs with if-statements we need to be clear about what we mean, or what we intend our programs to do. Sometimes when you say "if" you mean "when" and vice-versa. Just be on the lookout.

Do this activity: Flowcharts - Activity Guide

Open up Code Studio Watch all the videos Read all the examples Do the lessons

"The last problem ("it's the weekend") was tricky. What made it hard "The last problem ("it's the weekend") was tricky. What made it hard? How did you end up solving it?" What made it hard was that you needed to check more than one condition at the same time. You needed to say "it's saturday OR sunday". That's more than one condition to check. So a solution (using only what we know so far) is to nest if-statements. Nesting if statements is one way to check more than one condition at a time.

Turn in/Show me: #14 Text Password Checker # 16 Movie Entrance #17 Guessing Game #18 It’s the Weekend!