Selection Structures Relational and Logical Operators; If Statements.

Slides:



Advertisements
Similar presentations
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.
Advertisements

CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
5.04 Apply Decision Making Structures
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
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.
Chapter 5 - VB.Net by Schneider
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Chapter 5 - Visual Basic Schneider1 Chapter 5 Decisions.
Determine whether each curve below is the graph of a function of x. Select all answers that are graphs of functions of x:
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks.
Chapter 4 - VB 2008 by Schneider1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks 5.4 A Case Study: Weekly.
1 2.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
MIS 216 Exam1 Review Spring What to expect Questions like those on the home works and on the quizzes Evaluate code Create code Multiple choice and.
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
22/11/ Selection If selection construct.
Repetition Structures
Chapter 51 Logical Operators Used with Boolean expressions Not – makes a False expression True and vice versa And – will yield a True if and only if both.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks 4.4 Input via User Selection.
31/01/ Selection If selection construct.
# 1# 1 Nested If Statements in VBA What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf? CS 105 Spring 2010.
These Guys? Wait, What? Really?  Branching is a fundamental part of programming  It means taking an action based on decision  The decision is dependent.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Computer Science Up Down Controls, Decisions and Random Numbers.
Chapter 4 - VB 2008 by Schneider1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks.
1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks 5.4 A Case Study: Weekly Payroll.
Week 4 Relational and Logical Operators Dr. Jennifer Cunningham.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
Chapter 4 - VB 2008 by Schneider
Selection Statements by Ahmet Sacan
Chapter 4: Control Structures
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 – Decisions 4.1 Relational and Logical Operators
Topics The if Statement The if-else Statement Comparing Strings
Boolean Expressions and If statements
Comparing and Ordering Rational Numbers
VB Decisions, Conditions & If
Chapter 5 - Visual Basic Schneider
If selection construct
Logical Operations In Matlab.
Visual Basic – Decision Statements
VB Decisions & Conditions
Conditional Logic Presentation Name Course Name
SELECTIONS STATEMENTS
JavaScript conditional
Chapter 5 Decisions.
Visual Basic Programming
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
GCSE Computing:: Selection (IF statements)
Presentation transcript:

Selection Structures Relational and Logical Operators; If Statements

An If statement allows a program to decide on a course of action based on whether a condition is true or false If condition Then action1 Else action2 End If

Relational Operators

Relational Operator Examples 1 <= 1 1 < 1 “car” < “cat” “Dog” < “dog”

Logical Operators And –condition1 And condition2 is true if both condition1 and condition2 are true otherwise it evaluates to false Or –condition1 Or condition2 is true if either condition1 or condition2 (or both) are true otherwise it evaluates to false Not –Not condition1 is true if condition1 is false, and is false if condition1 is true

Logical Operator Examples Assume n = 4 and answ = “Y” –(2 < n) And (n < 6) –(2 < n) Or (n = 6) –Not (n < 6) –(answ = “Y”) And (answ = “y”) –(answ = “Y”) Or (answ = “y”) –Not (answ = “y”)

If Statements An If statement allows a program to decide on a course of action based on whether a condition is true or false If condition Then action1 Else action2 End If

If Statement Example Private Sub cmdComputeTip_Click() Dim cost As Single, tip As Single cost = Val(InputBox("Enter cost of meal:")) tip = cost * 0.15 If tip < 1 Then tip = 1 End If picTip.Print "Leave "; FormatCurrency(tip); " for the tip." End Sub

If Statement Example Private Sub cmdQuestion_Click() Dim name As String 'Ask for first Ronald McDonald name = UCase(InputBox("Who was the first Ronald McDonald?")) picAnswer.Cls If name = "WILLARD SCOTT" Then picAnswer.Print "Correct." Else picAnswer.Print "Nice try." End If End Sub

Nested If Example Private Sub cmdComputeBalance_Click() Dim balance As Single, amount As Single balance = Val(InputBox("Current balance:")) amount = Val(InputBox("Amount of withdrawal:")) If (balance >= amount) Then balance = balance - amount picBalance.Print "New balance is "; FormatCurrency(balance) If balance < 150 Then picBalance.Print "Balance below $150" End If Else picBalance.Print "Withdrawal denied." End If End Sub

Private Sub cmdFindLarger_Click() Dim Num1 As Integer Dim Num2 As Integer Num1 = Val(txtFirstNumber.Text) Num2 = Val(TxtSecondNumber.Text) If Num1 > Num2 Then picResult.Print "The larger number is"; Num1 ElseIf Num2 > Num1 Then picResult.Print "The larger number is"; Num2 Else picResult.Print "The two numbers are equal" End If End Sub ElseIf Example