ICS 3U Tuesday, September 21st.

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

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
3 Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. Conditions can be formed using the.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
The If/Else Statement, Boolean Flags, and Menus Page 180
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
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: 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.
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.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Decision Making Selection structures (if....else and switch/case)
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Selection Statements. Introduction Today we learn more about learn to make decisions in Turing ▫Nested if statements, ▫case statements.
Chapter#3 Part1 Structured Program Development in C++
Decisions in Python Boolean functions. A Boolean function This is a function which returns a bool result (True or False). The function can certainly work.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to programming in java Lecture 11 Boolean Expressions and Assignment no. 2.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
Conditional or Decision Logic
Sequence, Selection, Iteration The IF Statement
Debugging and Random Numbers
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
IF statements.
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4 – Control Structures Part 1
Javascript Conditionals.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Microsoft Visual Basic 2005 BASICS
Relational & Logical Operators
Phil Tayco Slide version 1.0 Created Oct 2, 2017
And now for something completely different . . .
Computers & Programming Languages
Building Java Programs
Control Structures: Selection Statement
If selection construct
Conditions and Boolean Expressions
Java Programming Control Structures Part 1
Flow Control Statements
Logical Operations In Matlab.
Selection Control Structure
Visual Basic – Decision Statements
Selection Statements.
If Statements.
Conditional Logic Presentation Name Course Name
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Boolean Expressions to Make Comparisons
Beginning C Lecture 3 Lecturer: Dr. Zhao Qinpei
CHAPTER 4: Conditional Structures
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
CHAPTER 5: Control Flow Tools (if statement)
EECE.2160 ECE Application Programming
Control Structures: Selection Statement
Selection Control Structure
Control Structures.
Presentation transcript:

ICS 3U Tuesday, September 21st

Conditional Statements If Statements If statements are used in code to make decisions ... If a condition is true, then something is done If the condition is false, something else may happen An example would be doing one thing if the user enters an even number, and something else if an odd number is entered

Basic Structures Three types of if statements: Simple If If / Else If / Else If / Else Simple If Something is done if the boolean expression is true If (boolean expression) then Statements that are executed for true

Basic Structures (con’t) If / Else Something is done when true, and something else is done when false If (boolean expression) then - statements evaluated if true Else - statements evaluated if false

Basic Structures (con’t) If / Else If / Else Multiple boolean expressions are included If (boolean expression) then - statements if this boolean expression is true Else If (boolean expression) then - statements if first expression is false, but this one is true Else - statements if all boolean expressions are false

Boolean Expressions / Variables A boolean expression is an expression that evaluates to true or false (a boolean result) They involve relational operators (<, >, !=, ==, <=, >=) The result of a boolean expression can be assigned to a boolean variable. Boolean variables are used to enhance the readability of programs, and to help with debugging When boolean variables are converted to integers, they have a value of 0 or 1 (0 = false, 1 = true)

Boolean Expressions / Variables Example Example: if age > 18 price = 12.50 Better example (use of boolean variable): adult = age > 18 if adult

Logical Operators In addition to the relational operators, we can use logical operators: AND && OR || NOT ! These are used to combine boolean expressions to create new and more complext boolean expressions Remember they have an order of operations: NOT, AND, OR  NAO

Logical Operator Examples Example: if adult && passholder then price = 10.50 if tired || hungry then go home if ! happy then tell a joke

Logical Operator Rules AND && - both expressions have to be true This course is ICS3U and all students are 15 yrs old This course is ISC 3U and the teacher is Miss Nieuwenhuis OR || - only one of the expressions needs to be true It is a day 1 or it is a day 2 This course is ICS 3U or all students are 15 yrs old NOT ! – the opposite ! (age < 15) ! (weather is sunny)

ActionScript Syntax

Work Time!  Programming Exercises – see wiki NEW Programmers – Stay UP HERE with me for some additional examples

Examples Write if statements for the following: User has entered in a number, output if the number is greater than 100 User has entered in their mark, output if the grade is a pass or a fail User has entered in their age, compare their age to yours output younger, same age or older.