Relational Operators. > greater than < less than >= greater than or equal to <= less than or equal to <> not equal to = equal to

Similar documents
Function: function procedures and sub procedures share the same characteristics, with

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

IS 320 Spring 96 Page 1 Exam 1. Please use your own paper to answer the following questions. Point values are shown in parentheses.

Review for Exam 2. IF Blocks. Nested IF Blocks. School of Business Eastern Illinois University. Represent computers abilities to make decisions

2Practicals Visual Basic 6.0

Angel International School - Manipay 1 st Term Examination November, 2015

Review. October 20, 2006

Chapter 8 Statement-Level Control Structures

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

Angel International School - Manipay 1 st Term Examination November, 2015

Programming with visual Basic:

HELP - VB TIPS. ANIMATE AN IMAGE BOX Insert a module. In this module, create a global variable: Global x

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

(Subroutines in Visual Basic)

Chap 6 - Introduction to HDL (b)

PROGRAM 1: SIMPLE CALCULATOR

The Control Properties

EMPLOYEE PAYROLL SYSTEM

CMPT 110 MIDTERM OCTOBER 18, 2001

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

3. Can every Do-Loop loop be written as a For-Next loop? Why or why not? 4. Name two types of files that can be opened and used in a VB program.

Revision for Final Examination (Second Semester) Grade 9

AIM To analyze, design and develop code for Online Course Reservation System using Rational Rose software

ElseIf: Another Conditional Statement

Before We Begin. Introduction to Computer Use II. Overview (1): Winter 2006 (Section M) CSE 1530 Winter Bill Kapralos.

( ) 1.,, Visual Basic,

Lecture 5 Tao Wang 1

SMS 3515: Scientific Computing. Sem /2015

Chapter 8. Statement-Level Control Structures

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

The following expression causes a divide by zero error:

Programming in C. Pointers and Arrays

Introductory Notes: Condition Statements

Remainder Cordial Labeling of Graphs

20. VB Programming Fundamentals Variables and Procedures

Visual Basic 6 Lecture 7. The List Box:

Type Storage Range of Values

Chapter Goals. 3.1 The if Statement. Contents 1/30/2013 DECISIONS

Flow Control. CSC215 Lecture

8. Decision-Making Statements. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Microsoft Visual Basic 2005: Reloaded

CSU211 Exam 2 Fall 2007

Java+- Language Reference Manual

PROJECT ELECTRONIC CONTROL GAS INJECTION SYSTEM

Chapter 4 The If Then Statement


Chapter 8 Statement-Level Control Structure

Lecture 15 MATLAB II: Conditional Statements and Arrays

Mathematical Computing

Visual Basic

VB komande. Programiranje 1

7 Control Structures, Logical Statements

Crystal Reports. Overview. Contents. Using Crystal Reports Print Engine calls (API) in Microsoft Visual Basic

LAMPIRAN A PROGRAM FLOWSTONE

Chapter 8. Statement-Level Control Structures

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Intrinsic Numeric Operations

Chapter 4 Decisions. Section 4.1 Relational and Logical Operators. 1. Asc("A") is 65. What is Asc("C")? (A) 66 (B) 67 (C) 68 (D) "C" B

C++ Program Flow Control: Selection

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

Trees. CS 5010 Program Design Paradigms Lesson 6.2

โปรแกรมช วยทดสอบหม อแปลงกระแส

ECE468 Fall 2003, Final Exam

Lecture no

An InputBox( ) function will display an input Box window where the user can enter a value or a text. The format is

CSc 372. Comparative Programming Languages. 36 : Scheme Conditional Expressions. Department of Computer Science University of Arizona

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Ch. 7: Control Structures

Herefordshire College of Technology Centre Edexcel BTEC Level 3 Extended Diploma in Information Technology (Assignment 1 of 3)

ISA PCI Peripherals Connect Interface ISA. Enhanced Parallel Port EPP

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

CS Programming I: Branches

Algorithms. M. R. C. van Dongen. ucc. LaTEX and Friends Algorithms. Marc van Dongen. Algorithms and Listings

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Lecture 5. Review from last week. Selection Statements. cin and cout directives escape sequences

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Chapter 4: Making Decisions

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

Programming with Python

Chapter 4: Making Decisions

CSc 520 Principles of Programming Languages

COGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control

Python: Functions. Thomas Schwarz, SJ Marquette University

Algebraically Speaking Chalkdust Algebra 1 Fall Semester

Visual Basic Visual Basic

( &% class MyClass { }

Sample Paper 2010 Class XII Subject Informatic Practices

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

DECISION MAKING STATEMENTS

CS 3L (Clancy) Solutions and grading standards for exam 1

Lecture Using ListBox and ComboBox Controls In Visual Basic 6: list box

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Chapter 8. Statement-Level Control Structures ISBN

LN #2 (3 Hrs) Variables, Sequence Boolean Logic & Selection CTPS Department of CSE,Coimbatore

Visual Basic. The Integrated Development Environment. Menu Bar

Chapter Two: Program Design Process and Logic

Access VBA programming

Parsing Instrument Data in Visual Basic

Making Decisions. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

Transcription:

Relational Operators > greater than < less than >= greater than or equal to <= less than or equal to <> not equal to = equal to

Conditions Conditions are expressions that involve relational operators Example: A < B, A <> B, etc. where A, B are either numbers, or strings

More complex conditions More complex conditions can be formed using expressions involving simple conditions and logical operators. cond1 And cond2 cond1 Or cond2 Not cond1

What does A < B mean for two strings A, B? A precedes B lexicographically in the ANSI character set (as in a dictionary)

Controlling Program Flow Conditional Execution If condition Then do action1 Else action2 End If

Pseudo code If condition is true Then execute code 1 Else execute code 2 End If

Example Given two numbers A and B, print A if A < B, and print B if B <= A If A < B Then Print A Else Print B End If

The Else part can be absent Example: If A < B Then Print A End If

Pseudo code for another example: Input two numbers A, B If A < B then print the difference A-B Else print the difference B-A Lets consider the code below:

Private Sub Command1_Click() Dim A, B, D As Integer A = Text1.Text B = Text2.Text If A < B Then D = B - A Print D Else D = A - B Print D End If End Sub

Private Sub Command1_Click() Dim A, B, D As Integer A = Val(Text1.Text) B = Val(Text2.Text) If A < B Then D = B - A Print D Else D = A - B Print D End If End Sub

Another If statement can be in the Then or Else part of the If statement Pseudo code: Input two numbers A, B If A < B Then Print A-B Else If A > B Then Print B-A Else Print A and B are equal

Private Sub Command1_Click() Dim A, B As Integer A = Val(Text1.Text) B = Val(Text2.Text) If A < B Then Print B - A Else If A > B Then Print A - B Else Print "A and B are equal" End If End If End Sub

The ElseIf clause If there are more than two alternatives, the ElseIf clause is a cleaner, more readable way to write the code It is equivalent logically to the previous code

If cond1 Then action1 ElseIf cond2 Then action2 ElseIf cond3 Then action3 Else action4 End If

Private Sub Command1_Click() Dim A, B As Integer A = Val(Text1.Text) B = Val(Text2.Text) If A < B Then Print B - A ElseIf A > B Then Print A - B Else Print "A and B are equal" End If End Sub

What if we had more alternatives? If cond1 Then action1 ElseIf cond2 Then action2 ElseIf cond3 Then action3 Else action4 End If

Select Case Statement If we have to choose among a set of alternatives, a Select Case statement is cleaner, more readable Select Case statement is equivalent to If statement with ElseIf

Select Case Statement Select Case selector Case valuelist1 action1 Case valuelist2 action2.. Case Else action for fall through End Select

Select Case choices are determined by the value of an expression called selector Case valuelist1 action1 action1 is carried out if the value of selector lies in the range specified in valuelist1

valuelist1, valuelist2, etc. can be one or more of the following types of items seperated by commas: A constant A variable An expression An inequality sign preceded by Is and followed by a constant, variable, or expression A range expressed as a To b, where a,b are constants, variables or expressions

Example Select Case Grade Case Is > 90 yourgrade = A Case Is >= 80 yourgrade = B End Select If Grade is 95, it lies in both ranges > 90, and >= 80. The first valuelist item containing the selector is chosen, and corresponding action carried out

Example Select Case Grade Case Is > 90 yourgrade = A Case Is > 80 yourgrade = B Case Is > 70 yourgrade = C Case Else Please retake the Final End Select

Private Sub Command1_Click() Select Case Val(Text1.Text) Case Is > 90 Print "your grade is A" Case Is > 80 Print "your grade is B" Case Is > 70 Print "your grade is C" Case Is > 60 Print "your grade is D" Case Else Print Please retake Final" End Select End Sub

Case Else (and corresponding action) is optional Can we replace above Select Case by the following If Then statements? If Val(Text1.Text) > 90 Then Print your grade is A If Val(Text1.Text) > 80 Then Print your grade is B...