Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.

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

Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
CS0007: Introduction to Computer Programming
Practical Programming COMP153-08S Lecture 6: Making Decisions Part II.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Compunet Corporation1 Programming with Visual Basic.NET Selection Structure If-Else Week 4 Tariq Ibn Aziz.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
true (any other value but zero) false (zero) expression Statement 2
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
Decisions in Python elif. A new keyword elif A contraction of “else if” Used to tie two if statements (or more) together into one structure Syntax – elif,
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
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.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Logical Operators Jumps Logical Operators The different logical operators found in Java Rational Operators The different rational operators found in Java.
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.
Variables, operators, canvas, and multimedia Dr. José M. Reyes Álamo.
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
Controlling Program Flow with Decision Structures.
CPS120: Introduction to Computer Science Decision Making in Programs.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Variables, operators, canvas, and multimedia Dr. Reyes.
Chapter 4 Select … Case Multiple-Selection Statement & Logical Operators 1 © by Pearson Education, Inc. All Rights Reserved. -Edited By Maysoon.
Computer Science Up Down Controls, Decisions and Random Numbers.
 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.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Chapter 4 The If…Then Statement
UNIT 4 Lesson 13 If statements.
Operator Precedence Operators Precedence Parentheses () unary
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Microsoft Visual Basic 2005 BASICS
Topics The if Statement The if-else Statement Comparing Strings
Chapter 3: Introduction to Problem Solving and Control Statements
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Visual Basic – Decision Statements
Selection Statements.
Conditional Logic Presentation Name Course Name
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
The if Statement Control structure: logical design that controls order in which set of statements execute Sequence structure: set of statements that execute.
CS2011 Introduction to Programming I Selections (I)
Relational Operators.
Chapter 5 Decisions.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Presentation transcript:

Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression is a part of a complete program statement that asks a True­or-False question about a property, a variable, or another piece of data in the program code. For example, the conditional expression price < 100 evaluates to True if the Price variable contains a value that is less than 100, and it evaluates to False if Price contains a value that is greater than or equal to 100.

Comparison Operators used in Conditional Expressions =Equal to <>Not equal to >Greater than <less than >=Greater than or equal to <=Less than or equal to

If... Then Decision Structures When a conditional expression is used in a special block of statements called a decision structure, it controls whether other statements in your program are executed and in what order they're executed. You can use an If...Then decision structure to evaluate a condition in the program and take a course of action based on the result. In its simplest form, an If... Then decision structure is written on a single line: If score >= 20 Then Label1.Text = "YOU win!"

If... Then Decision Structures In its simplest form, an If... Then decision structure is written on a single line: If score >= 20 Then Label1.Text = "YOU win!" Score >=20 is evaluated to determine whether the program should set the Text property of the Label1 object to “You win!" If the Score variable contains a value that's greater than or equal to 20, Visual Basic sets the Text property; otherwise, it skips the assignment statement and executes the next line in the event procedure. This sort of comparison always results in a True or False value. A conditional expression never results in maybe.

Boolean expressions Expressions that can be evaluated as True or False are also known as Boolean expressions, and the True or False result can be assigned to a Boolean variable or property. You can assign Boolean values to certain object properties or Boolean variables that have been created by using the Dim statement and the As Boolean keywords.

Logical Operators You can test more than one conditional expression in If.. Then and Elself clauses if you want to include more than one selection criterion in your decision structure. The extra conditions are linked together by using one or more of the logical operators: AndIf both conditional expressions are True, then the result is True. OrIf either conditional expression is True, then the result is True. NotIf the conditional expression is False, then the result is True. If the conditional expression is True, then the result is False. XorIf one and only one of the conditional expressions is True, then the result is True. If both are True or both are False, then the result is False. (Xor stands for exclusive Or.)

Select Case Decision Structure With Visual Basic, you can also control the execution of statements in your programs by using Select Case decision structures. A Select Case structure is similar to an If... Then... ElseIf structure, but it's more efficient when the branching depends on one key variable, or test case. You can also use Select Case structures to make your program code more readable.

Select Case Decision Structure The syntax for a Select Case structure looks like this: Select Case variable case value1 statements executed if value1 matches variable case value2 statements executed if value2 matches variable case value3 statements executed if value3 matches variable case Else statements executed if no match is found End Select